I created an interface with one method, the ability to copy the contents of one object to another object of the same type (the actual functionality is not relevant to the issue).
public interface IDeepClonable
{
void DeepClone<T>(T other);
}
I am having problems with the correct implementation.
I would like it to be implemented (where is it inside ClassA that implements IDeepClonable)
public void DeepClone<ClassA>(ClassA other)
{
this.A = other.A;
}
However, this does not work, since the βotherβ object is not recognized by the compiler as an instance of the ClassA class (why?)
This also does not work, since it gives "restrictions for a parameter of type T, which must correspond to the interface method (...).
public void DeepClone<T>(T other) where T : ClassA
{
this.A= other.A;
}
I can solve all problems by changing the interface to take an object instead of a general restriction, but I was hoping for a more elegant solution.
, , .