Reflection and overriding
-
Here is the problem, I have an abstract class that has a public property (type = bool). When setting the Property = true, I need to make sure two virtual functions, in the class, were overridden. I don’t want to make them abstract because they don’t usually need to be overridden. So, I looked for some way to use reflection to do this, but I haven’t made much headway. Any help is greatly appreciated.
-
Here is the problem, I have an abstract class that has a public property (type = bool). When setting the Property = true, I need to make sure two virtual functions, in the class, were overridden. I don’t want to make them abstract because they don’t usually need to be overridden. So, I looked for some way to use reflection to do this, but I haven’t made much headway. Any help is greatly appreciated.
ACorbs wrote: I need to make sure two virtual functions, in the class, were overridden. 2 ways I can think of: - use
BindingFlags.DeclaredOnly
when enquiring the Type for the method(s), if none returned, no override. This is limited to the class your in, might not be what you are looking for. - get the method(s) via reflection, and check for the absence of theNewSlot MethodAttributte
flag. This means it the method is overriden in the inheritance chain. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots -
ACorbs wrote: I need to make sure two virtual functions, in the class, were overridden. 2 ways I can think of: - use
BindingFlags.DeclaredOnly
when enquiring the Type for the method(s), if none returned, no override. This is limited to the class your in, might not be what you are looking for. - get the method(s) via reflection, and check for the absence of theNewSlot MethodAttributte
flag. This means it the method is overriden in the inheritance chain. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots -
ACorbs wrote: You wouldn't happen to know the proc cost of these? You just need to check once for each type, after that you can just lookup whether the class is overriden or not eg via a static Hashtable in the base class. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots