How to get instance reference

Sep 1 2011 7:26 PM
Hy

I have a class like this:
public class myClass
{
        public string fieldA;
        public Datatime fieldB;
        ...
}

I would like to be able to provide a property kind of like this:
        public List<object> Fields
        {
                get
                {
                }
        }

that returns the actual fields of the instance - not "just" the value.

I can enumerate them using reflection, but I cannot seem to get from the FieldInfo object to the actual fueld on the instance.
The class is not sealed and I would like my Fields property to return the fields added in inherited classes also - if possible.

any feedback on how to proceed?

Best regards

Poul Lindholm Christiansen


Answers (7)