vendredi 6 juillet 2018

C# - Calling functions from class variable in abstract class through reflection

I'm trying to use Reflection to call a function off of an class variable which is inside of an instance of my object.

I have a class that's defined similarly to this:

public abstract class Foo : IDisposable
{
    public Bar c { get; }
    <...snip...>
 }

Bar is a sealed class but I don't think that's related to my problem. Under a non-reflection case using this class looks like this:

Foo myFoo = someOtherObject.GetFoo();
myFoo.c.someFunc();

I need to do the same using reflection but can't access the c variable inside of my constructed Foo object.

I've already confirmed that my myFoo object is constructed correctly using reflective function calls, but I can't access the instance variable. Other topics have suggesting doing myFoo.GetType().GetFields() and then iterating through the fields to get the one I want but GetFields() returns nothing in both cases (reflection or no), so I'm not sure if the issue has something to do with it being defined as abstract or something else.

Is there another way for me to get the class variable?





Aucun commentaire:

Enregistrer un commentaire