jeudi 5 mars 2015

How can I set a string property to null by reflection with C# [on hold]

I have an object and I have the name of a string property. How can I set the value to null?


I have tried the following but unforunatly c# converts null to the string "Null"



Data data = new Data();
PropertyInfo propertyInfo = data.GetType().GetProperty("StringProperty");
string valOrNull = null;
propertyInfo.SetValue(data, valOrNull, null);
//data.StringProperty is now "Null" instead of null





Aucun commentaire:

Enregistrer un commentaire