runtime Type Casting help

Hey guys, I'm trying to load data from an external text file and the property looks a bit like this:
ZGF2.Objects.Key,-90,-10 the Key class is an extension of the Dynamic class and so will be all the other things I load from the text file. My question is this; When I go and load the Key object, I do so like this:

//str = ZGF2.Objects.Key,-90,-10 public static Dynamic FromStr(string str) { Dynamic val = new Dynamic(); str = str.trim(); string[] splitproperties = str.split(','); val.Position = new Vector2( float.Parse(splitproperties[1]), float.Parse(splitproperties[2])); Type valtype = Type.GetType(splitproperties[0]); return (typeof(valtype)) val; //Why doesn't this work and what should I be doing instead? } 

by Soundless_Pr via /r/csharp

Leave a Reply