dynamic assigning of class properties
-
I have a text file which contains different properties of a class (like integers, doubles, integer-array (more numbers divided by commas),..) I want to read and assign. Well, i managed to read all the key=value Pairs in that textfile and the looping through all the properties of that class. Now I want to assign these values to their appropriate property of the class. But how can i convert now the values (which are logically strings) to the datatype they have to be? I need something like object Convert.FromString(string str) Or I compare the read in keys with the properties from the class so that I know to which Datatype the string has to be converted, but on this way I need a way to typecast dynamically.
-
I have a text file which contains different properties of a class (like integers, doubles, integer-array (more numbers divided by commas),..) I want to read and assign. Well, i managed to read all the key=value Pairs in that textfile and the looping through all the properties of that class. Now I want to assign these values to their appropriate property of the class. But how can i convert now the values (which are logically strings) to the datatype they have to be? I need something like object Convert.FromString(string str) Or I compare the read in keys with the properties from the class so that I know to which Datatype the string has to be converted, but on this way I need a way to typecast dynamically.
-
I have a text file which contains different properties of a class (like integers, doubles, integer-array (more numbers divided by commas),..) I want to read and assign. Well, i managed to read all the key=value Pairs in that textfile and the looping through all the properties of that class. Now I want to assign these values to their appropriate property of the class. But how can i convert now the values (which are logically strings) to the datatype they have to be? I need something like object Convert.FromString(string str) Or I compare the read in keys with the properties from the class so that I know to which Datatype the string has to be converted, but on this way I need a way to typecast dynamically.
-
object System.Convert.ChangeType(object value, Type conversionType, IFormatProvider provider);