public interface IFoo { }
public abstract class IFooDerived : IFoo { }
public class Foo : IFooDerived { }
public interface IBar { }
public abstract class IBarDerived : IBar { }
public class Bar : IBarDerived { }
public interface IExample<out A, B> where A : IFoo where B : IBar
{
A Foo(B b);
}
public class Example : IExample<Foo, Bar>
{
static Example example = new Example();
static Example()
{
Example ex = example;
IExample<IFoo, IBar> ex_huh = ex; //How can I do this?
//Or is there a way where I can say I don't care, but I still want to reference ex, like this:
IExample<object,object> ex_huh2 = ex;
//Or:
IExample<, > ex_huh2 = ex;
ex_huh2.Foo(new Bar()); //And still call Foo?
}
public Foo Foo(Bar b)
{
throw new NotImplementedException();
}
}
在上面的例子中,我如何在不知道其泛型类型的情况下对静态示例变量进行降级和引用,但仍能够调用“A Foo(B b)”?c#协议属性/通用访问的泛型?
是否有这样做的强类型的方式?