You can get a type object for a generic / (not generic) type with typeof:
public static T Parse<T>(String value) { object result = default(T); var typeT = typeof (T); if (typeT == typeof(Guid)) { result = new Guid(value); } else if (typeT == typeof(TimeSpan)) { result = TimeSpan.Parse(value); } else { result = Convert.ChangeType(value, typeT); } return (T)result; }
My simple method returns T. And this is the key. It must be shared so that the developer can specify the type of return value. If a method does not return a common one and accepts only one, there are several reasons to make it general. To avoid box / unbox operations in method arguments or to solve a situation when a method takes an argument of different types that are not inherited from a common base class / interface. And that is none of your business. Thus, the method in your code should not be general. Just enter the argument as IFeature and use is / as / GetType ():
private static void Activate(IFeature feature) { if (feature is FeatureImplementationA) {
source share