-
Notifications
You must be signed in to change notification settings - Fork 1
Tuple extensions
Old-school System.Tuple has one major disadvantage - it's unable to be decomposed into a set of variables. Insted of it, the basic class library proposes to use the set of properties named Item1, Item2, etc.
This library offers you a method to decompose the tuple directly into variables.
int i;
string s;
DateTime d;
var result = tuple.Tie(out i, out s, out d);
This scenario decomposes the tuple of three elements into three distinct variables. The function returns the origin tuple, thus allowing to chain the calls.
In some case it's very useful to update some objects' properties by the values stored in a tuple. Say, you have an object with three properties that should be updated with the values of the tuple.
tuple.Tie(result,
v => v.IntProperty,
v => v.StringProperty,
v => v.DateTimeNullableProperty);
This scenario updates the properties of result object with the values of the given tuple.
And if you have more than one object, then it is possible to update the properties of these object by one call.
tuple.Tie(
result1, v => v.IntProperty,
result2, v => v.StringProperty,
result2, v => v.DateTimeNullableProperty);
In this scenario, the result1 object's property named IntProperty will be updated and result2 object's properties named StringProperty and DateTimeNullableProperty will be updated as well.