View Single Post
  #1 (permalink)  
Old March 7th, 2005, 08:01 AM
jacob jacob is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen, , Denmark.
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic Cast in C#

I am trying to figure out how to do a more general method for doing some attribute retrieval, however my problem is that I do not know how to do the dynamic cast in C#, and it must be possible.

Previously I did something like this...
Code:
attribute = (MyType)Attribute.GetCustomAttribute(t, typeof(MyType));
... which worked perfectly, however I want to put this into a more general method, where MyType is given as argument (Type) to the method, so I would get something like this...
Code:
attribute = Attribute.GetCustomAttribute(t, attributeType);
... but it still needs the casting of the result from GetCustomAttribute, so how do I do this? I tried to use the as keyword but with no luck.

Thanks, Jacob.
__________________
Danish audio books for download at http://www.lytenbog.dk (Danske lydbøger til download).