Ejemplo n.º 1
0
        public static void TupleRestTypeConstructionTest()
        {
            var builder = new ValueTupleBuilder();

            Equal(typeof(ValueTuple), builder.Build());
            builder.Add <DateTime>();
            Equal(typeof(ValueTuple <DateTime>), builder.Build());
            builder.Add <string>();
            Equal(typeof(ValueTuple <DateTime, string>), builder.Build());
            builder.Add <int>();
            Equal(typeof(ValueTuple <DateTime, string, int>), builder.Build());
            for (int i = 0; i < 5; i++)
            {
                builder.Add <bool>();
            }
            Equal(8, builder.Count);

            var tupleType = builder.Build();

            Equal(typeof(ValueTuple <bool>), tupleType.GetField("Rest")?.FieldType);

            var members = builder.Build(Expression.New, out _);

            Equal(typeof(DateTime), members[0].Type);
            Equal(typeof(bool), members[7].Type);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a new component into tuple.
 /// </summary>
 /// <param name="itemType">The type of the tuple component.</param>
 public void Add(Type itemType)
 {
     if (Count < 7)
     {
         items.Add(itemType);
     }
     else if (Rest is null)
     {
         Rest = new ValueTupleBuilder()
         {
             itemType
         }
     }
     ;
     else
     {
         Rest.Add(itemType);
     }
 }
Ejemplo n.º 3
0
        public static void TupleTypeConstructionTest()
        {
            var builder = new ValueTupleBuilder();

            Equal(typeof(ValueTuple), builder.Build());
            builder.Add <DateTime>();
            Equal(typeof(ValueTuple <DateTime>), builder.Build());
            builder.Add <string>();
            Equal(typeof(ValueTuple <DateTime, string>), builder.Build());
            builder.Add <int>();
            Equal(typeof(ValueTuple <DateTime, string, int>), builder.Build());
            for (int i = 0; i < 16; i++)
            {
                builder.Add <bool>();
            }
            Equal(19, builder.Count);
            var tupleType = builder.Build();

            Equal(typeof(ValueTuple <, , , , , , ,>), tupleType.GetGenericTypeDefinition());
        }