- Say I have an interface
IFoowith a methodFooMethod()and a classFoo : IFoo. - Say I have another interface
IBarwith methodBarMethod()and a classBar : IBar. - Now I can create an object
Foo obj1 = Foo()and callobj1.FooMethod(). - I can also create an object
Bar obj2 = Bar()and callobj2.Bar().
- I can now make a method that accepts e.g. an object of
IFoo, e.g.obj1, such that
void FooExample(IFoo fooObj)
=> fooObj.FooMethod();
FooExample(obj1); // Because typeof(obj1) == Foo and Foo : IFoo
- Can I somehow now make a method:
void CombinedExample((IFoo, IBar)foobarObj)
{
foobarObj.Foo();
foobarObj.Bar();
}
I know I can make a new (empty) interface IFooBar: IFoo, IBar such that I can now change the type of the parameter of CominedExample can be changed to IFooBar foobarObj, but I am particularly curious if there is a way of combining two (or even more) interfaces / classes to create a temporary object that inherits from these types without having to create a new empty type that just exists to combine those other types which I might only need in very few occasions.
Any suggestion to solve this 'problem' are welcome!