views:

396

answers:

1

Hello,

I'm a newbie whitebelt with WCF.

I have a namespace: http://schemas.datacontract.org/2004/07/System/ArgumentException.

I'm looking to take that string and convert it into a CLR type so that I end up with typeof(ArgumentException).

Is this possible? :)

Thank you, MichaelD

A: 

Check out Activator.CreateInstance(). Here's an example of its usage:

dim obj as Object = Activator.CreateInstance("ArgumentException")

In your case you can parse the type name out of the namespace and pass it as a parameter to CreateInstance().

http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx

Keith
I'm familiar with this method/class. However, I'm wanting a way of passing in the provided URI as a whole without any parsing involved. There is something somewhere in the framework that allows this. I know it. :)
I'm not aware of any built in framework methods to do this. But you can accomplish it by combining the above method with reflection. According to this - http://msdn.microsoft.com/en-us/library/ms731045.aspx - all CLR types have the same namespace format. Any other namespace can be assumed to belong to your custom data contracts.But if you find a framework solution, please let me know!
Keith