Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: Jeff Mason <je.mason@xxxxxxxxxxx>
- Date: Mon, 31 Jul 2006 12:14:33 -0400
On 31 Jul 2006 08:32:37 -0700, tommaso.gastaldi@xxxxxxxxxxx wrote:
I anticipated your observation by 2 using 2 classes:I really appreciate your help and interest here.
MyDerivedClass_Instance
MyDerivedClass
both display correct attributes, although the same type is used in the
gettype.
Can you make an example where this scheme would fail, so that we can
fix it ?
Let's concentrate on the issue where no class instance is involved, and the shared
method on the base class is invoked through the derived class (since that's were my
problem lies).
Suppose I define two classes both decorated with their own version of the attribute:
<MyCustomAttribute("Default1", "Default2")> _
Public Class MyDerivedClass
Inherits MyBaseClass
End Class
<MyCustomAttribute("Hi", "Tom")> _
Public Class AnotherDerivedClass
Inherits MyBaseClass
End Class
How would the assignment of the 'classtype' variable in the base's shared method be
made? As you originally suggested, it was:
Dim classtype As Type = GetType(MyDerivedClass)
but now I have two classes, MyDerivedClass AND AnotherDerivedClass, both of which
derive from MyBaseClass, and for both of which I'd like to evaluate each's attribute,
as, say:
Dim x as string = MyDerivedClass.S_ValueFromMyAttribute(1)
Dim y as string = AnotherDerivedClass.S_ValueFromMyAttribute(1)
I would hope to return x = "Default1" and y = "Hi".
It seems to me that GetType won't work here as it needs an explicit Type as its
argument. Since there can be multiple classes that inherit from the base, I don't
know that Type in the base class, as it is only known at run-time when the shared
method is invoked.
I'm thinking that some other form of reflection is required to get the Type of the
derived classin the base's shared method. I have no idea what that might be...
-- Jeff
.
- Follow-Ups:
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: tommaso . gastaldi
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- References:
- Custom Attributes, Shared methods, Derived classes and reflection
- From: Jeff Mason
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: tommaso . gastaldi
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: Jeff Mason
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: tommaso . gastaldi
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: Jeff Mason
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: tommaso . gastaldi
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: Jeff Mason
- Re: Custom Attributes, Shared methods, Derived classes and reflection
- From: tommaso . gastaldi
- Custom Attributes, Shared methods, Derived classes and reflection
- Prev by Date: Re: Font with Bold and italic
- Next by Date: Re: How do you set file permissions?
- Previous by thread: Re: Custom Attributes, Shared methods, Derived classes and reflection
- Next by thread: Re: Custom Attributes, Shared methods, Derived classes and reflection
- Index(es):
Relevant Pages
|