'Can this class structure be better represented?

public class Foo<T> { internal Foo() { } }
public sealed class Foo_SByte : Foo<SByte> { }
public sealed class Foo_Byte : Foo<Byte> { }
public sealed class Foo_Short : Foo<Int16> { }
public sealed class Foo_UShort : Foo<UInt16> { }
public sealed class Foo_Int : Foo<Int32> { }
public sealed class Foo_UInt : Foo<UInt32> { }
public sealed class Foo_Long : Foo<Int64> { }
public sealed class Foo_ULong : Foo<UInt64> { }
public sealed class Foo_Char : Foo<Char> { }
public sealed class Foo_Float : Foo<Single> { }
public sealed class Foo_Double : Foo<Double> { }
public sealed class Foo_Bool : Foo<Boolean> { }
public sealed class Foo_Decimal : Foo<Decimal> { }
public sealed class Foo_String: Foo<string> { }
public class Foo_Struct<T> : Foo<T> where T : struct { }
public class Foo_Enum<T> : Foo<T> where T : Enum { }

// Now T is immutable

My objective is to restrict use of Foo to all potential value types, which I am semantically (maybe incorrectly) assuming to be equivalent to saying "all immutable types"

In other words, I dont want T to be a reference type.

The implementation doesn't change between Bars. I only want the guarantee of T restricted to immutable types.

Have I missed any (excluding the simple types, which I am aware of)?

Is there a better way?

Edit: Ok, I fully implemented it. Now all uses of Foo<T> are guaranteed to be immutable. (If not, please tell me what types I missed. Or try to inherit from a Foo to prove me wrong).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source