作为对此的后续问题
public interface IFeature { }
public class FeatureA : IFeature { }
IFeature a = new FeatureA();
Activate(a);
private static void Activate<TFeature>(TFeature featureDefinition) where TFeature : IFeature
{
}
Run Code Online (Sandbox Code Playgroud)
我没有理解,一旦将FeatureA其转换IFeature为泛型方法,它将始终IFeature作为类型参数获取.
我们有一项服务,为我们提供了一个列表功能(List<IFeature>).如果我们想迭代这些特性,在泛型方法中传递每个特征,我想没有办法在泛型方法中获得具体类型而不是
由于反射非常昂贵,我想使用动态强制转换.以这种方式调用方法有什么缺点吗?不知怎的,我这样做时感觉很脏:-)