From microsoft documentation, Type.GetType
can be case-insensitive in .NET 4.5. Unfortunately, this is not available in WinRT (Metro/Modern UI/Store apps).
Is there a known workaround ? Because I have to instantiate objects from a protocol which have all the string representations in uppercase.
Example : from "MYOBJECT", I have to instantiate MyObject
.
I currently use Activator.CreateInstance(Type.GetType("MYOBJECT"))
, but due to the case sensitivity, it does'nt work.
Thanks
Do you know the assembly you're loading the types from? If so, you could just create a case-insensitive
Dictionary<string, Type>
(usingStringComparer.OrdinalIgnoreCase
) by callingAssembly.GetTypes()
once. Then you don't need to useType.GetType()
at all - just consult the dictionary:EDIT: Having seen that these are all in the same namespace, you can easily filter that :