In my application, some of the entities implement interface A, others implement interface B, and some implement both A and B. How can I force code that looks at these entities that implement both A and B to use the derived interface for A and B?
Here's some examples:
Interface A
public interface IActive
{
DateTime? StartEffDT { get; set; }
DateTime? EndEffDT { get; set; }
}
Interface B
public interface ISecured
{
object SecurityToCheck { get; set; }
}
Interface A and B
public interface IActiveSecured : IActive, ISecured
{
}
Method Example
public void ExampleMethod1(IActive x) { }
public void ExampleMethod2(ISecured y) { }
public void ExampleMethod3(IActiveSecured z) { }
Is there a way to force ExampleMethod1 to only take IActive, but not IActiveSecured?
public void UpdateItem(IActive item) {
//update the item, if it is currently active
}
If I tried to call UpdateItem with an IActiveSecured item, it would work. No surprise, that's how inheritance works. But what if I want to ensure that you can't call UpdateItem with an IActiveSecured, because the security needs to be checked to make sure that the user is authorized to update the item?
Thanks for the help!