vendredi 19 janvier 2018

How to change a property getter at runtime in C#

I have a class with a property that looks like this:

public class Hmd{
    Transform HmdTransform{
        get{ device.GetTransform(); }
    }
}

device.GetTransform() gets the Transform from a driver.

Now I want to change the get method of the property at runtime, to something like:

public class Hmd{
    private Transform hmdTransform;
    Transform HmdTransform{
        get{ return hmdTransform; }
    }
}

Is there any way to do that? I would have to create a new member and change the getter. If I can't create a new member could I just change the device.GetTransform() line? I assume I would have to use Reflection.Emit?

Additional complication: All of this is in Unity, so I can only use Mono.





Aucun commentaire:

Enregistrer un commentaire