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#協議屬性/通用訪問的泛型?
是否有這樣做的強類型的方式?