theraot / Theraot

Backporting .NET and more: LINQ expressions in .net 2.0 - nuget Theraot.Core available.
MIT License
158 stars 30 forks source link

Mark ITuple as public and support indexer #185

Closed CreateAndInject closed 2 years ago

CreateAndInject commented 2 years ago

Rename ITupleInternal to ITuple, mark it as public and support this[] & Length like in .NET Framework

For example, I can't do something like this in Theraot.Core

        static void Main()
        {
            Test(1, "han", ("aa", 1), (1, 0, "test", 1));
        }

        static void Test(params object[] args)
        {
            foreach (object obj in args)
            {
                if (obj is ITuple tuple)
                {
                    for (int i = 0; i < tuple.Length; i++)
                        Console.WriteLine(tuple[i]);
                    if (tuple.Length == 2)
                    {
                        Console.WriteLine(tuple[0] is string);
                        Console.WriteLine(tuple[1] is int);
                    }
                }
            }
        }
CreateAndInject commented 2 years ago

By the way, both Tuple and ValueTuple should implement ITuple

CreateAndInject commented 2 years ago

Merged in my own project