In C # 7, we can implement the Deconstruct method, which will be called when an object is assigned to a tuple with the corresponding types.
I wonder why Microsoft decided to implement this as a "magic method." There is this specially named method that is not inherited anywhere, and if you name it correctly and place the correct parameters, then you can assign this object to the appropriate tuple.
I would suggest that the development team create an interface for this purpose.
Sort of:
public interface IDecontructible<T1> { void Deconstruct(out T1 a); } public interface IDecontructible<T1, T2> { void Deconstruct(out T1 a, out T2 b); } public interface IDecontructible<T1, ... ,Tn> { void Deconstruct(out T1 a, ... ,out Tn n); }
Of course, there should be more interfaces with a different number of parameters.
Is there an obvious reason for this design choice that I am missing?
source share