GetCustomAttributes And Generic Delegates?

Dec 15, 2010

I am struggling to get the syntax for the reflection call GetCustomAttributes ... at least I don't seem to be able to get hold of the custom attribute which I've decorated a particular method with. The complicating factor maybe that I have passed that method into an extension method as a generic delegate. (The other, more likely, complicating factor is that I'm not sufficiently familiar with reflection or what happens when you pass a method as a parameter like this!)

The code appears to run, and when I step it, the count returned from the GetCustomAttributes is 1. I can't work out how to get hold of that custom parameter

[Code]...

View 11 Replies


ADVERTISEMENT

Specify Generic Types On Delegates?

Nov 15, 2010

Maybe I am just not reading the MSDN documentation correctly, but given a function that takes in one string parameter and returns type T, how can this be specifed as a shared function using Func()?

MSDN says Func(Of In T1, Out TResult), but all of their examples use the same data type, i.e., Func(Of String, String). I want to do Func(Of In String, Out T), where T is arbitrary (but I can constrain it if necessary by a base class). I want it shared/static at the class level, yet the encapsulating class will itself not be a generic class. It seems in this specific scenario, it's impossible to do what I want because the compiler would have no way of knowing what Type T is at runtime.

So is it possible to do generics on delegates or anonymous lambda expressions in VB.net (not C#)?

View 1 Replies

.net - GetCustomAttributes?

Sep 13, 2010

<AttributeUsage(AttributeTargets.Property)> _
Private Class CustomAttrib
Inherits Attribute

[code].....

View 4 Replies

GetCustomAttributes On An Anonymous Delegate?

Dec 14, 2010

I am struggling to retrieve custom attributes from a method. As you can see, the method ProcessXML has a custom attribute. The method itself gets passed into an anonymous delegate and then, in that context, I'm looking to get its custom attributes, but I'm not sure quite how to do it.

Here's my code

Public Sub UpdateXML()
Dim errors = New Errors
Dim xml = <testxml>

[code]....

View 1 Replies

C# - ICustomAttributeProvider.GetCustomAttributes(...): Design Strangety?

Jun 23, 2010

The MSDN Documentation: MemberInfo.GetCustomAttibutes Method (Type, Boolean) states in the remarks:This method ignores the inherit parameter for properties and events. To search the inheritance chain for attributes on properties and events, use the appropriate overloads of the Attribute.GetCustomAttributes method.This basically means that this implementation's second parameter (bool inherit) is ignored for event members and property members. However, calling the ttribute.GetCustomAttributes(MemberInfo,Type,bool) variety of this operation does not. Why would they seemingly ignore the inherit attribute arbitrarily on 2 forms of member types?

View 1 Replies

Delegates And Multicast Delegates In .NET

Mar 27, 2009

What are Delegates and Multicast Delegates in VB.NET? How do I use them? provide a simple example to illustrate the concept.

View 1 Replies

Is There A Concept Of "Generic Structure" Similar To Generic Collections, Generic Classes

Dec 16, 2009

We have migrated our Vb6 application to VB.NET using a third party tool. Now we are in a process of Refactoring and introducing object oriented concepts in the application.

In VB6, we were using structures in many places. As a part of introducing object oriented programming,

1. is it a good idea of changing all Structures to Classes? or Is there a concept of "Generic Structure" similar to Generic collections, Generic classes?

2. Can some one guide me any source containing guide lines or best practices for applications that are migrated to VB.NET from VB6 and implementing object oriented programmaing.

View 3 Replies

.net - Can A Generic Version Of A Derived Class Override A Base Method Using The Generic Type

Apr 13, 2012

Consider:

Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful

[code]....

But this gives the following error:

Public Overrides Function ParseValue(sValue As String) As Boolean'
cannot override 'Public Overridable Function ParseValue(sValue As String) As Object'
because they differ by their return types.

I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.

View 2 Replies

.net - Determining A Generic Type At Runtime In Non-Generic Class

Aug 14, 2010

I have a Journal that records entries for different types: Journal(Of ParentT)

[Code]....

View 2 Replies

Construct A Generic Interface Class With Generic Functions

Nov 25, 2011

I am trying to construct a generic interface class with generic functions. My goal was to use this to implement multiple worker classes for database interaction that have the same basic functionality. Each class will deal with different object for example, category, product or supplier but unless the the functions in the interface are generic that this won't work.This is the interface code that I have but I don't know if I have done it correctly. [code]

View 2 Replies

.net - Creating A Generic List Of A Generic Type

Jun 30, 2011

I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:

Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName

[Code]....

The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.

View 2 Replies

Generic Cannot Instantiate Instance Of The Generic Type With New?

Feb 8, 2012

I am trying to write a generic method, to avoid code duplication, which will create or activate a Form as an MDI children, based on its type. But I have to lines in error (see comments).

[Code]...

View 4 Replies

VS 2008 Accessing Something With A Generic Generic?

Jun 19, 2012

If i have an object that implements an interface (and don't know the exact object) i can call a sub (DoSomething) by going:

vb
Dim iObj = trycast(something, iInterface)
if iObj isnot nothing then
iObj.DoSomething()
end if

How can I do this for a Generic? such as...

vb
Public Class TestClass(of T)
Public sub DoSomething()
....
end class

View 2 Replies

XML Serializing Delegates

Feb 10, 2010

I have a class that I want to be serializable but contains a public instance of delegate that, apparently can't be serialized: [Code] Is there a way to make it serializable however?

View 4 Replies

Multithreading - Modify A Generic Invoke Method To A Generic BeginInvoke Method?

Oct 7, 2010

I have been using a pretty slick generic invoke method for UI updating from background threads. I forget where I copied it from (converted it to VB.NET from C#), but here it is: Public Sub InvokeControl(Of T As Control)(ByVal Control As t, ByVal Action As Action(Of t))

[Code]....

View 1 Replies

Constrain Arguments NOT To Be Delegates?

Feb 3, 2012

Consider these two functions[code]...

My question is: what is the right way to accomplish this to resolve the ambiguity so that I can pass value or references types and get overload 2, but pass Functions and get overload 1? Can I constrain the types in some way to make this happen?

View 1 Replies

Displays One Of The Two Delegates Per Invocation?

Mar 27, 2011

I've been tinkering with Delegates, and now Multicast delegates. Every time I invoke two delegates It only displays one of the two delegates per invocation.

[Code]...

View 6 Replies

Extra Variable For Delegates?

Feb 17, 2011

[Code]....

So func is a function that accepts a string and return a string. In practice, internally, func also utilizez text1, text2. In fact, func can even be a member function with access the object that owns it (something like me or this operator).

And all that can be accomplished without changing the signature of func? How do the compiler do this?

View 2 Replies

Interface Of Multiple Delegates?

Nov 29, 2009

is there a way to create an interface of delegates? Sub dostuff(byval arg1 as dele1)works, problem is that i have 8 delegates, so i will have to give it 8 signatures. that isn't so bad, but the problem is that when there are various combinations of signatures it gets real real bad.

Sub dostuff(byval arg1 as [Delegate])works, but it allows me to accept delegates beyond the 8 that i wanted (it's like declarign arguments with base Object)could i be able to do this:

Sub dostuff(byval arg1 as Idele1to8)

View 1 Replies

Lambda - Anonymous Delegates In .net (pre Vb9)?

Apr 7, 2009

Is it possible to create anonymous delegates in vb.net version 8 or earlier? If so, could someone provide an example of the syntax?

View 2 Replies

Multithreading Or Delegates With WMI Calls?

Jul 12, 2011

I have a VBNET app to scan my Active Directory using WMI calls and return some basic informaiton such as Dell Model name, current user logged on, Dell Service Tag etc my issue is the app becomes unresponsive whilst it scans and i have to wait for it to finish looping before i can work with it, in the past a do events used to suffice

I think Multithreading is the way i may need to go, whats the best approach? I tried to use Delegates but it doesnt seem to have made any difference

below is my for next loop code that calls the functions, the last section "Private Sub Button1_Click" down is the Delegate code i attempted

[Code]...

View 3 Replies

Use Delegates For Handling An Event?

May 7, 2009

I can come up with, if I understood the solution better, I could probably phrase a better subject line.[code]...

View 2 Replies

VS 2008 Delegates And Backgroundworker?

Jun 4, 2010

I am having trouble with getting a delegate to work properly.Here's my

[Code]...

View 14 Replies

What Is Difference Between Delegates And Events

Feb 11, 2010

What is the difference b/w Delegates and Events. I have little bit confusion. Where delegates are used, and when we have to used delegates. Can, you give some examples(both delebates and events) in vb.net.

View 6 Replies

Why Are Event Delegates Required

May 26, 2009

I was going through tutorials and found the topic of Events and Delegates. However, I fail to understand why should this be required ? Instead of having to raise events, can't one just call the necessary procedure ?Sorry for posing this basic question. Any replies or even links to existing posts are welcome. [Also not sure if this question strictly falls under VB.NET category.]

View 4 Replies

.net - Utilize Optional Parameters In Delegates?

Aug 6, 2010

However, I am wondering if there are any workarounds or plans for incorporating this feature into VB.NET in the future?What I'd like to do:

Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, optional ByRef BufferPosition As Integer = 0) As T
'Implementation of a func that matches the delegate'
Class A
Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
....

In the absence of specifying "optional" inside the actual delegate itself, it'd at least be nice to be able to do it in the function implementation only:

Public Delegate Function Deserializer(Of T)(ByRef Buffer() As Byte, ByRef BufferPosition As Integer) As T
'Implementation of a func that matches the delegate'
Class A
Public Function Deserialize(Byref Buffer() as Byte, optional Byref BufferPosition as integer = 0)
....

At least this second way, the functions for the delegate will always have a value mapped to each parameter, although some may come from the function side and not the calling side.

View 2 Replies

Checking How Many Delegates Are Attached To An Event

Jan 30, 2010

is there a way to check how many delegates are attached to an event, let's saymybutton.Click has 10 handlers, 5 by using the Handles keyword and another 5 added by using the AddHandler method (well this is not the point, then point is that i do not know how many handlers there will be). and i would want to create another button that had all 10 handlers of mybutton.Click attached to its Click event as well.

View 6 Replies

DataReceived Event And Delegates Reference?

Dec 3, 2009

I'm looking for a reference that can explain the concept and use of the DataReceived event and Delegates subject.The reference has to be pretty simple as I'm an "old dog attempting to learn a new trick". I'm not ignorant of things programming, but am ignorant of things dealing with serial communication in VB2005.I already have a couple of O'Rielly books ("VB2005 Cookbook", "VB2005 Desktop Reference") and I have a book that deals with serial communication from a Jan Axle-something. Neither O'Rielly books have any info, and the Axle-someting book's remotely related examples are too confusing for this slow learner.

View 6 Replies

Delegates - Calling Subroutines From Lambda In .net?

Oct 7, 2009

I find myself calling functions from lambdas frequently as the provided delegate does not match or does not have sufficient parameters. It is irritating that I cannot do lambda on subroutines. Each time I want to do this I have to wrap my subroutine in a function which returns nothing. Not pretty, but it works.

Is there another way of doing this that makes this smoother/prettier? I have read that this whole lambda inadequacy will probably be fixed in VS2010/VB10 so my question is more out of curiosity.

[Code]...

View 2 Replies

Delegates, Background Worker And DataGridView?

Jun 5, 2011

I have a form with a DataGridView control. When i load the form, i fill the control with several records. Now sometimes it can be 1 to 30, but sometimes it could be 10000+ records.Now, what i'm trying to do is to grid.AutoResizeColumns

As you can imagine, when i have 30 records it goes like the Flash, but the more records, the longer it takes; obviously..So, for now i have a ugly label saying "WAIT PLEASE" and waitcursor=true; Yes, horrible, i know...

So i tried to do the following:I created a form called frmWAIT, and have a timer in it that shows 4 pictures at 250ms intervals, to make some kind of animation.In my Primary form, i added a BackgroundWorker, and in the DoWork Event, i tried to grid.AutoResizeColumns and it won't do it.

[Code]...

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved