How can I write an optimal Swap ( T a, T b ) algorithm in C#? : My mission for this lonely Friday night is to write a C# swap algorithm 

    public void Swap<T> ( ref T a, ref T b ) 
    {
       // ... 
    } 

that works on any class or data type `T` and is as efficient as possibe. Help critique the method I've built up so far. First of all, is it correct? How can I make it Skeet-certified?

    public void Swap<T> ( ref T a, ref T b ) 
    {
       // Not sure yet if T is a data or value type. 
       // Will handle swapping algorithm differently depending on each case.
       Type type = T.GetTyle();
       if ( type.IsPrimitive() || type == typeof(Decimal) )
       {
           // this means the we can XOR a and b, the fastest way of swapping them
           a ^= b ^= a ^= b;
       }
       else if ( type.IsValueType() ) 
       {
          // plain old swap in this case
          T temp = a; 
          a = b; 
          b = temp;
       }
       else // is class type
       {
          // plain old swap???        
       }
    } 

Other questions: 

 - What the overhead of the type checking cancel out any performance benefits of the XOR swap?
 - Would the way this is handled be any different for a value type versus a class type if I wanted to optimize the performance of each case? 
 - Is there a better way to check whether two elements are XORable?
 - Let's say I wanted a version of this method that takes value types, like 

     public void Swap<T> ( ref T a, ref T b ) where T : struct
     {
       // 
     }

obviously I don't want to make copies of the entire structs in case they're very big. So I want to do the equivalent of what is in C++ 

    template <typename T>
    void PointerSwap<T> ( T * a, T * b )
    {
        T * temp = a;
        a = b;
        b = temp;
    }

Now, I know that in C# you can get in the structs by ***boxing*** them into a class (reference type), but isn't there major overhead in doing that? Is there no way of simply using an integral type reference (so-called "memory address" in C++) as a parameter? 

C++ makes so much more sense than C# ... 