I have some entities, that may or may not inherit from other objects, but they will implement an interface, lets call it IMyInterface.
public interface IMyInterface {
long MyPropertyName { get; set; }
}
An object will always implement this interface, but it may have been implemented on a class that the object inherits from. How can i get the name of the class that has this interface implemented?
Examples should give these results
public class MyClass : IMyInterface {
}
public class MyHighClass : MyClass {
}
public class MyPlainClass {
}
public class PlainInheritedClass : MyPlainClass, IMyInterface {
}
If i pass in MyClass, it should return MyClass, because MyClass implements the interface.
If i pass in MyHighClass, it should return MyClass, because MyClass was inherited, and it implements the interface.
If i pass in PlainInheritedClass, it should return PlainInheriedClass, because it inherited from MyPlainClass, but that did not implement the interface, PlainInheritedClass did
EDIT/ EXPLAINATION
I am working with entity framework 6. I have created a sort of recycle bin feature, that allows users to delete data on the database, but really it just hides it. In order to use this feature, an entity must implement an interface, which has a particular property against it.
Most of my entities do not inherit from anything, but just implement the interface. But i have a couple of entities that do inherit from another object. Sometimes the object they are inheriting from implement the interface and sometimes the object itself will implement the interface.
When i set the value, i use the entities and entity framework works out which table to update. But when i "unset" the property, i am using my own SQL statements. In order to create my own SQL statements, i need to find out which table has the column i need to update.
I cannot use entity framework to load the entities based on the type only, because .Where
doesnt exist on a generic DbSet class.
So i want to create an SQL statement similar to this
UPDATE tableX SET interfaceProperty = NULL WHERE interfaceProperty = X