My particular problem:
I have a string which specifies an aribitrary type in a configuration class
Config.numberType = 'System.Foo';
where Foo is a type like Decimal or Double
I use Type.GetType(Config.numberType) to return the corresponding type.
How do I get from that type to being able to use, System.Foo.TryParse() ?
Some further related queries
TryParse()can be accessed fromSystem.Foo.TryParse()as well asfoo.TryParse(). Does this meanfoois some kind of class in C#? This seems weird to me thatint,doubleetc are actually not just modifier keywords.- How can you declare variables under these circumstances? –
varis not universally usable it seems i.e. only in local scope etc.
As many have said – there isn’t a direct route. I expect one close option is
TypeConverter:Of course, you may need
try/catchto handle exceptions. Such is life.