Simple Reflenction
-
Hey all - Really quickly, how can I dynamically change a property with reflection? For example, if I have a class:
class Foo{ public bool Enabled{...} }
I can dynamically load the class with the following:Type t = System.GetType("David.Demo.Foo"); // how can I set Enabled to false?
Thanks much, *->>Always working on my game, teach me *->>something new. cout << "dav1d\n"; -
Hey all - Really quickly, how can I dynamically change a property with reflection? For example, if I have a class:
class Foo{ public bool Enabled{...} }
I can dynamically load the class with the following:Type t = System.GetType("David.Demo.Foo"); // how can I set Enabled to false?
Thanks much, *->>Always working on my game, teach me *->>something new. cout << "dav1d\n";afronaut wrote: Type t = System.GetType("David.Demo.Foo"); // how can I set Enabled to false?
PropertyInfo prop = t.GetProperty("Enabled"); // f is an instance of Foo prop.SetValue(f, false, null);
Charlie if(!curlies){ return; } -
afronaut wrote: Type t = System.GetType("David.Demo.Foo"); // how can I set Enabled to false?
PropertyInfo prop = t.GetProperty("Enabled"); // f is an instance of Foo prop.SetValue(f, false, null);
Charlie if(!curlies){ return; }