T
tshad
I have a function that uses goes through all the properties in an object and
sets the value to null. The problem is that it uses a method in the
property to set it. At the moment I just do:
private void SetPropertiesToNull(object objectToInspect)
{
Type objectType = objectToInspect.GetType();
PropertyInfo[] properties = objectType.GetProperties();
foreach (PropertyInfo property in properties)
{
// Set each property to null
property.SetValue(objectToInspect, null, null);
}
}
But I need to change it so that it does something like:
objectToInspect.SetValuetoNull(property.Name)
but this won't work as it doesn't know what type of object it is and I would
have to do something like:
((SubjectObject)objectToInspect).SetValuetoNull(property.Name)
I can get the "SubjetObject" from objectToInspect.GetInfo(), but can't
figure out how to use that dynamically to cast objectToInspect.
Is there a way to do this?
Thanks,
Tom
sets the value to null. The problem is that it uses a method in the
property to set it. At the moment I just do:
private void SetPropertiesToNull(object objectToInspect)
{
Type objectType = objectToInspect.GetType();
PropertyInfo[] properties = objectType.GetProperties();
foreach (PropertyInfo property in properties)
{
// Set each property to null
property.SetValue(objectToInspect, null, null);
}
}
But I need to change it so that it does something like:
objectToInspect.SetValuetoNull(property.Name)
but this won't work as it doesn't know what type of object it is and I would
have to do something like:
((SubjectObject)objectToInspect).SetValuetoNull(property.Name)
I can get the "SubjetObject" from objectToInspect.GetInfo(), but can't
figure out how to use that dynamically to cast objectToInspect.
Is there a way to do this?
Thanks,
Tom