You can inherit your common class from a common base:
abstract class FooBase { } abstract class FooBase<TEnum> : FooBase, IFoo<TEnum> where TEnum : struct, IConvertible, IFormattable, IComparable { public TEnum MyEnum { get; set; } } public static TFooClass GetFoo<TFooClass>() where TFooClass : FooBase, new() { TFooClass fooclass = new TFooClass(); return fooclass; }
But you will not be able to access the MyEnum property with a common FooBase restriction. (And how could you, without specifying the type?)
This, or you need to add another type parameter in GetFoo :
abstract class FooBase<TEnum> : IFoo<TEnum> where TEnum : struct, IConvertible, IFormattable, IComparable { public TEnum MyEnum { get; set; } } public static TFooClass GetFoo<TFooClass, TEnum>() where TFooClass : FooBase<TEnum>, new() where TEnum : struct, IConvertible, IFormattable, IComparable { TFooClass fooclass = new TFooClass(); return fooclass; }
UPDATE: Another thing that I could point out is that if you find that you need to call this method GetFoo many times, then if you put it in an instance class instead of a static class, you can click one or both type arguments to a class instead of always specifying it in a method. This may make some code a little less verbose, but in fact, only if you call this method a lot. Example:
public sealed FooFactory<TEnum> where TEnum : struct, IConvertible, IFormattable, IComparable { public static TFooClass GetFoo<TFooClass>() where TFooClass : FooBase<TEnum>, new() { TFooClass fooclass = new TFooClass(); return fooclass; } } ... var factory = new FooFactory<SomeEnum>(); var foo1 = factory.GetFoo<SomeFooClass1>(); var foo2 = factory.GetFoo<SomeFooClass2>();