Unfortunately there is no way to make a general purpose extension method that will work with all Tuple
combinations. C# has no such facility. A different extension must be given for every Tuple
type that you want it to work on
Giving C# Tuples order extension methods or similar
Question
public static class tuple_extentions
{
public static Vector2 mul(this Tuple<Vector2 v, float f>)
{
return v * f;
}
}
public void main()
{
Tuple.Create(new Vector2(4, 3), 2).mul(); // works
Tuple.Create(2, new Vector2(4, 3)).mul(); // doesn't work
}
Is there a way to achieve this or something similar with multiple definitions not being required and still working with Intelisence, with or without extensions and the Tuple class.
3 such parameters for example would require up to 6 definitions.
Solution
OTHER TIPS
You can't abstract over the arity of tuples, unfortunately. To get this functionality you need some sort of heterogenous list. http://jeff.cutsinger.org/blarg/2011/03/27/heterogeneous-lists.html has a nice set up to expand upon.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow