Expando object - creating a dynamic class and reading the property types in a unit test
-
dynamic returnObject = new ExpandoObject() as IDictionary;
// Other code actions here
var EnterData = (IDictionary)returnObject
EnterData.Add("myColumn", typeof(int));
Now when I debug a test that I have created I can see the value type has been set to int. but I would like to add a test to this, purely for my own learning
var keypair = EnterData.FirstOrDefault(p=> p.Key == "myColumn");
var properties = keypair.GetType().GetGenericArguments();
var ValueType = properties[1];which always returns a type object, is there a way to get the type that I have assigned to the keyvaluepair?
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
dynamic returnObject = new ExpandoObject() as IDictionary;
// Other code actions here
var EnterData = (IDictionary)returnObject
EnterData.Add("myColumn", typeof(int));
Now when I debug a test that I have created I can see the value type has been set to int. but I would like to add a test to this, purely for my own learning
var keypair = EnterData.FirstOrDefault(p=> p.Key == "myColumn");
var properties = keypair.GetType().GetGenericArguments();
var ValueType = properties[1];which always returns a type object, is there a way to get the type that I have assigned to the keyvaluepair?
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
Maybe I'm doing or reading it wrong, but wouldn't that be
string myValueType = keypair.Value.ToString();
That should return "System.Int32", and the first part of the pair is always a string.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
Maybe I'm doing or reading it wrong, but wouldn't that be
string myValueType = keypair.Value.ToString();
That should return "System.Int32", and the first part of the pair is always a string.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Thanks Eddie, it worked.. Silly me, while looking my brain thought everything must complicated so I ignored all the easy stuff. :doh:
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
Thanks Eddie, it worked.. Silly me, while looking my brain thought everything must complicated so I ignored all the easy stuff. :doh:
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON