假设我们有一个像这样的代码部分:
IProduct product = ProductCreator.CreateProduct(); //Factory method we have here
SellThisProduct(product);
//...
private void SellThisProduct(IProduct product)
{
//.. Do something here
}
//...
internal class Soda : IProduct
{}
internal class Book : IProduct
{}
Run Code Online (Sandbox Code Playgroud)
如何推断哪个产品实际传递到方法中的SellThisProduct()方法?
我想如果我说GetType()或者它可能会返回IProduct类型.