V
visor7
Hi, i've been trying to investigate how to traverse through an object
instance properties or fields with no success. I have read about
IEnumerable interface but that seems to apply only to collection of
objects. What i want to do actually is to traverse through each
property of an instance and if possible, assign a null value...
something like this:
MyClass instance = new MyClass();
instance.property1 = "A string";
instance.property2 = 21;
then, once i have assigned values, i would like to be able to do
something like this:
foreach (object obj in myinstance)
{
obj = null;
}
What i meant above with object is that of course i may have an int, a
string, etc. so i dont know what type of data i may get and so i want
to traverse the properties despite its type. I dont know if this is
possible, i've read a lot that implementing IEnumerable interfaces it
can be donde but i just cannot find any real example. I also found that
using generics i can handle the value type thing.
Any help would be really appreciated, a URL with an example would be
great
Thanks.
instance properties or fields with no success. I have read about
IEnumerable interface but that seems to apply only to collection of
objects. What i want to do actually is to traverse through each
property of an instance and if possible, assign a null value...
something like this:
MyClass instance = new MyClass();
instance.property1 = "A string";
instance.property2 = 21;
then, once i have assigned values, i would like to be able to do
something like this:
foreach (object obj in myinstance)
{
obj = null;
}
What i meant above with object is that of course i may have an int, a
string, etc. so i dont know what type of data i may get and so i want
to traverse the properties despite its type. I dont know if this is
possible, i've read a lot that implementing IEnumerable interfaces it
can be donde but i just cannot find any real example. I also found that
using generics i can handle the value type thing.
Any help would be really appreciated, a URL with an example would be
great
Thanks.