Answer by cdiggins for C# Parse string to type known at runtime
Here is what I consider to be a cleaner implementation of the answer from Scott Hanselman via Russell Troywest public static object Parse(Type t, string s) =>...
View ArticleAnswer by quicktrick for C# Parse string to type known at runtime
I had the same task to load variables of a class, using reflection. I load key/value pair strings from a file, then I parse the values basing on corresponding key variables' definitions from my...
View ArticleAnswer by Russell Troywest for C# Parse string to type known at runtime
TypeConverters are the way to go. Take a look here for a good example of what to do.Nicked straight from hanselmans blog:public static T GetTfromString<T>(string mystring){ var foo =...
View ArticleAnswer by rene for C# Parse string to type known at runtime
You can use the static Convert.ChangeType method for that. It takes an object as its first parameter and a Type instance you want to convert the object to. The return value is of the type you requested...
View ArticleAnswer by Xcalibur37 for C# Parse string to type known at runtime
I would recommend using MethodInfo on the property for the Parse method and see if the MethodInfo object is valid. Then, carry out the parse operation if...
View ArticleAnswer by Bradley Uffner for C# Parse string to type known at runtime
I believe that TypeConverters, Specifically StringConverter can help you with this problem.http://msdn.microsoft.com/en-us/library/system.componentmodel.stringconverter.aspx
View ArticleC# Parse string to type known at runtime
I have a file holding some of the variables of a class, and each line is a pair : variable, value. I'm looking for a way to load these at runtime (a-la XmlSerializer), using reflection.Is there a way...
View Article
More Pages to Explore .....