Generic Factory method to instantiate a derived class from the base class
问题 I am in the process of creating a factory method which uses a generic abstract type parameter to return the instance of the concrete derived type using reflection. For eg. public abstract class ServiceClientBase : IServiceClient { } public abstract class Channel : ServiceClientBase { } public class ChannelImpl : Channel { } public class ServiceClientFactory { public T GetService<T>() where T : class, IServiceClient { // Use reflection to create the derived type instance T instance = typeof(T)