Is this C# 'hack' a bad idea? As C# doesn't have generic specialisation like C++ template specialisation and I wanted a way to be able to do it, I came up with a little hack that goes a bit like this:

    public sealed class Specialisation&lt;T&gt; 
    { 
        private Specialisation() { }
        private static Specialisation&lt;T&gt; instance = new Specialisation&lt;T&gt;();
        public static Specialisation&lt;T&gt; Instance { get { return instance; } }
    }
    public interface ISpecialisable&lt;T&gt;
    {
        T SpecialisedMethod(Specialisation&lt;T&gt; t);
    }
    public class Specialised : ISpecialisable&lt;int&gt;, ISpecialisable&lt;float&gt;
    {
        public double Value;
        public int SpecialisedMethod(Specialisation&lt;int&gt; t) { return (int)Value; }
        public float SpecialisedMethod(Specialisation&lt;float&gt; t) { return (float)Value; }
    }
    public static class Program
    {
        public static void Main()
        {
           Specialised s = new Specialised();
           s.Value = 12.3456789;
           Console.WriteLine(s.SpecialisedMethod(Specialisation&lt;int&gt;.Instance));
           Console.WriteLine(s.SpecialisedMethod(Specialisation&lt;float&gt;.Instance));
           Console.ReadKey();
        }
    }


Other than this not being the 'right way' to do things and being a complete mistreatment of the method overloading system, are there any possible side effects that could happen as a result of this horrible hack?

EDIT:

An applied example of specialisation in such a manner:

    // assume Specialisation is unchanged
    public interface IConvertible&lt;T&gt; // Not to be confused with System.IConvertible
    {
        T Convert(Specialisation&lt;T&gt; t);
    }
    public class ConvertMe : IConvertible&lt;int&gt;, IConvertible&lt;float&gt;
    {
        public double Value;
        public int Convert(Specialisation&lt;int&gt; t) { return (int)Value; }
        public float Convert(Specialisation&lt;float&gt; t) { return (float)Value; }
    }
    public static class Program
    {
        public static void Main()
        {
           ConvertMe c = new ConvertMe();
           c.Value = 12.3456789;
           Console.WriteLine(c.Convert(Specialisation&lt;int&gt;.Instance));
           Console.WriteLine(c.Convert(Specialisation&lt;float&gt;.Instance));
           Console.ReadKey();
        }
    }


EDIT:
Another example I just thought of as an extension of/alternative to the IConvertible&lt;T&gt; example. This technique allows the normal generic method syntax to be used externally, whilst allowing the class developer to internally define specialisations.

public interface IConvertible&lt;T&gt;
{
    T Convert(Specialisation&lt;T&gt; t);
    T Convert&lt;T&gt;();
}
// assume Specialisation&lt;T&gt; is unchanged
public class ConvertMe : IConvertible&lt;int&gt;, IConvertible&lt;float&gt;
{
    public double Value;
    int IConvertible&lt;int&gt;.Convert(Specialisation&lt;int&gt; t) { return (int)Value; }
    float IConvertible&lt;float&gt;.Convert(Specialisation&lt;float&gt; t) { return (float)Value; }
    public T Convert&lt;T&gt;() { return ((IConvertible&lt;T&gt;)this).Convert(Specialisation&lt;T&gt;.Instance); }
}
public static class Program
{
    public static void Main()
    {
        ConvertMe c = new ConvertMe();
        c.Value = 12.3456789;
        Console.WriteLine(c.Convert&lt;int&gt;());
        Console.WriteLine(c.Convert&lt;float&gt;());
        Console.ReadKey();
    }
}


This use of specialisation could be generalised to other applications in order to provide specialised behaviour. I won't add any more examples as the ones provided are long enough as it is, and I'm sure everyone here has the skill and imagination to find other applications of this pattern.
First of all, I would question the need for such interface. It makes sense for a type to hold a value, but I think it doesn't make much sense for a type to decide to what types to convert that value, or how.

Second, if you really do need this, then I would prefer each target type to have a separate method, like ConvertToInt() (or ConvertToInt32() if you follow the naming guidelines).

You don't necessarily need an interface for this, but even if you do, you're exchanging a small inconvenience in implementation (having to write few very simple interfaces with some repetition) for a big inconvenience in usage (having to write that Specialisation&lt;int&gt;.Instance every time and making the code less readable). So, I think using this approach is worth it even with interfaces.

Third, if you really do need this and you want to take advantage of generics, you could use explicit interface implementation and casting to decide to what type to convert. Something like:

public interface IConvertible&lt;T&gt;
{
    T Convert();
}

public sealed class ConvertMe : IConvertible&lt;int&gt;, IConvertible&lt;float&gt;
{
    public double Value;
    int IConvertible&lt;int&gt;.Convert() { return (int)Value; }
    float IConvertible&lt;float&gt;.Convert() { return (float)Value; }
}

public static class Program
{
    public static void Main()
    {
       ConvertMe c = new ConvertMe();
       c.Value = 12.3456789;
       Console.WriteLine(((IConvertible&lt;int&gt;)c).Convert());
       Console.WriteLine(((IConvertible&lt;float&gt;)c).Convert());
    }
}


This results in code that is shorter and more readable (I think) than your version.

One issue with it is that if you don't make ConvertMe sealed, trying to convert to an unsupported type becomes a runtime exception, instead of a compile-time error.