mercredi 25 février 2015

Check if a "Type" override a dynamic type

We are giving some repetitive jobs to a consultant company, we just have a few constraints that could not be checked by compilation, like a requirement to override a specific property in all class implementing a specific interface.


The property of the interface, which should be overrided in all classes has the following signature:



dynamic Definition{get;}


I found this stackoverflow question: How to find out if property is inherited from a base class or declared in derived?


Which is closed to my case, but in my case, the property is defined is inherited class and overrided in this one:



public class ClassA:IMyInterface
{
public virtual dynamic Definition{get{ /*return SomethingSpecificToClassA;*/}}
}

public class ClassB:ClassA
{
public override dynamic Definition{get{ /*return SomethingSpecificToClassB;*/}}
}


//The end goal is to know if ClassB has correctly overriden the property



bool overriden = typeof(ClassB)GetProperties(...).Any(p=>p.Name=="Definition");





Aucun commentaire:

Enregistrer un commentaire