private bool IsEqual(Tuple <int, int, decimal, int> item1, Tuple <int, int, decimal, int> item2)
        {
            PropertyInfo[] properties1 = item1.GetType().GetProperties();
            PropertyInfo[] properties2 = item2.GetType().GetProperties();
            object         value1;
            object         value2;

            Type type    = item1.GetType();
            bool isEqual = false;

            for (int i = 0; i < properties1.Length; i++)
            {
                value1 = properties1[i].GetValue(item1, null);
                value2 = properties2[i].GetValue(item2, null);

                if (value1 != null && value2 != null)
                {
                    isEqual = value1.Equals(value2);
                }

                if (!isEqual)
                {
                    break;
                }
            }

            return(isEqual);
        }
Exemplo n.º 2
0
        public void TupleCollection1()
        {
            var          value        = new Tuple <int> (1);
            const string data         = "0a0101";
            var          encodeResult = Encoder.Encode(value, value.GetType());

            Assert.AreEqual(data, encodeResult.ToHexString());
            var decodeResult = (Tuple <int>)Encoder.Decode(data.ToByteString(), value.GetType(), null);

            Assert.AreEqual(value, decodeResult);
        }
Exemplo n.º 3
0
        public void GetValueFromText_HandlesTuples()
        {
            var expectedValue = new Tuple <int, float>(5, 1.6f);

            Assert.AreEqual(expectedValue, UIHelpers.GetValueFromText(expectedValue.GetType(), "5:1.6"));

            var expectedValue2 = new Tuple <float, int>(3.1f, 33);

            Assert.AreEqual(expectedValue2, UIHelpers.GetValueFromText(expectedValue2.GetType(), "3.1:33"));

            var expectedValue3 = new Tuple <float, int>(4.1f, 18);

            Assert.AreEqual(expectedValue3, UIHelpers.GetValueFromText(expectedValue2.GetType(), "(4.1:18)"));
        }
Exemplo n.º 4
0
        public void GetFriendlyName_IsGenericWithMultipleTypes_ShouldBuildNameCorrectly()
        {
            var item   = new Tuple <int, int, string>(1, 2, "a");
            var result = item.GetType().GetFriendlyName();

            result.ShouldBe("Tuple<Int32,Int32,String>");
        }
Exemplo n.º 5
0
        public void PerformTuple()
        {
            Tuple <int, int, int> tuple = new Tuple <int, int, int>(1, 2, 3);                                                                                  //Hier wird ein Tupel mit 3 Integer Werten erstellt.

            Console.WriteLine($"{tuple}, Typ: {tuple.GetType()} | {tuple.Item1} + {tuple.Item2} + {tuple.Item3} = {tuple.Item1 + tuple.Item2 + tuple.Item3}"); //Hier werden alle Werte durch das "readonly" Property "Item#" dargestellt. Alle Items werden einzeln aufgerufen und addiert an die Konsole weitergereicht.
            Console.WriteLine();
            Console.WriteLine();
            tuple.Deconstruct(out int ersteZahl, out int zweiteZahl, out int dritteZahl);   //Mit ".Deconstruct()" kann man alle Items in dezidierte Variablen Verpacken und weiter im Code nutzen. Zwar könnte man auch neue Variablen definieren, jedoch sind die von .NET zur verfügung gestellten Methoden optimierter und reduzieren den Aufwand.
            Console.WriteLine($"{ersteZahl} + {zweiteZahl} + {dritteZahl} = {ersteZahl + zweiteZahl + dritteZahl}");

            ValueTuple <int, int, int> valueTuple = new ValueTuple <int, int, int>(1, 2, 3);  //Das ValueTuple ist das gegenstück zur Tuple-Klasse. Im gegensatz zum gewöhnlichen Tuple, besteht ein ValueTuple aus einem struct und ist somit viel effizienter und praktischer wenn es darum geht viele Objekte gleichzeitig zu verarbeiten.

            //Man sollte bedenken dass ValueTuple als structs nicht zu viele Items besitzen sollte. Idealerweise sollten es unter 10 Items sein aber das ValueTuple sowie das gewöhnliche Tuple akzeptieren bis zu 16 Items pro Instanz. Zum vergleich: Das DateTime-Objekt welches ebenfalls ein struct ist besitzt auch 16 Properties, es zählt aber zu den wenigsten structs die so viele Daten besitzen.

            valueTuple = tuple.ToValueTuple();  //Die Methode ".ToValueTuple()" Konvertiert ein gewöhnliches Tuple in ein ValueTuple mit allen Items die es besaß.
                                                //In diesem Fall hat ".ToValueTuple()" nichts verändert da "valueTuple" diese Werte(vom gewöhnlichen Tuple) bereits besitzt
            Console.WriteLine($"{valueTuple.Item1} + {valueTuple.Item2} + {valueTuple.Item3} = {valueTuple.Item1 + valueTuple.Item2 + valueTuple.Item3}");


            //Ein ValueTuple lässt sich auch einfach wie Folgt definieren:
            var i = (1, 2, 3);

            Console.WriteLine($"{i}, Typ: {i.GetType()} | {i.Item1} + {i.Item2} + {i.Item3} = {i.Item1 + i.Item2 + i.Item3}");

            PerformModernTuple();
        }
Exemplo n.º 6
0
    /// <summary>
    /// Copy values from sourceTuple into targetTuple.
    /// </summary>
    /// <typeparam name="T1">The type of target tuple.</typeparam>
    /// <typeparam name="T2">The type of source tuple.</typeparam>
    /// <param name="targetTuple">The target tuple.</param>
    /// <param name="sourceTuple">The source tuple.</param>
    /// <param name="sourceIndices">The indices of tuple elements to be copied from source tuple. Use -1 to ignore certain elements. Index values start from 1.</param>
    /// <returns>The modified target tuple if it's successfully assembled.</returns>
    public Tuple Assemble(Tuple sourceTuple, int[] sourceIndices)
    {
        TupleDescriptionAttribute tgtAttrib = this.GetType().GetCustomAttributes(typeof(TupleDescriptionAttribute), true)[0] as TupleDescriptionAttribute;

        if (sourceIndices.Length != tgtAttrib.Dimension)
        {
            return(this);
        }

        for (int i = 0; i < sourceIndices.Length; ++i)
        {
            int srcIndex = sourceIndices[i];

            if (srcIndex > Dimension)
            {
                continue;
            }
            if (srcIndex == -1)
            {
                continue;
            }

            this.GetType().GetField("Item" + (i + 1).ToString()).SetValue(this,
                                                                          sourceTuple.GetType().GetField("Item" + srcIndex.ToString()).GetValue(sourceTuple));
        }

        return(this);
    }
Exemplo n.º 7
0
        public Examples Example_005()
        {
            var a = ("cat", 1, 2, 3, 4, 5, 6, 7, 8, 9, "dog");

            // ValueTuple`8
            Console.WriteLine(a.GetType().Name);
            // ValueTuple`4
            Console.WriteLine(a.Rest.GetType().Name);

            var b = new Tuple <string, int, int, int, int, int, int, Tuple <int, int, int, string> >(
                "cat", 1, 2, 3, 4, 5, 6, new Tuple <int, int, int, string>(7, 8, 9, "dog")
                );

            // Tuple`8
            Console.WriteLine(b.GetType().Name);
            // Tuple`4
            Console.WriteLine(b.Rest.GetType().Name);

            var c = b.ToValueTuple();

            // True
            Console.WriteLine(a == c);
            // True
            Console.WriteLine(a.Rest == c.Rest);

            return(this);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            (int, string)myTuple1 = (1, "1");
            Console.WriteLine($"Type: {myTuple1.GetType()} , Base Type: {myTuple1.GetType().BaseType}");

            ValueTuple <int, string> myTuple2 = new ValueTuple <int, string>(2, "2");

            Console.WriteLine($"Type: {myTuple2.GetType()} , Base Type: {myTuple2.GetType().BaseType}");

            Tuple <int, string> myTuple3 = new Tuple <int, string>(3, "3");

            Console.WriteLine($"Type: {myTuple3.GetType()} , Base Type: {myTuple3.GetType().BaseType}");

            Console.WriteLine(ReturnTuple());

            Console.ReadLine();
        }
Exemplo n.º 9
0
        public void GenericTypeDetector_Tuple()
        {
            var tuple = new Tuple <string, int, Char>("", 10, 'c');

            TypeConverter converter = new TypeConverter();

            Assert.AreEqual(true, converter.IsGeneric(tuple.GetType()));
        }
Exemplo n.º 10
0
        public void Tuple_Simple_GetType()
        {
            Tuple <int, string> tuple1 = new Tuple <int, string>(10, "Hello");
            Tuple <int, int, int, int, int, int> tuple2 = new Tuple <int, int, int, int, int, int>(1, 2, 3, 4, 5, 6);

            Assert.AreEqual(typeof(string), tuple1.GetType().GetTupleItemType(1));
            Assert.AreEqual(typeof(int), tuple2.GetType().GetTupleItemType(4));
        }
Exemplo n.º 11
0
        /// <summary>
        /// When a query like "Find me all Persons that have Jonny or Jackie as their first, last or nick name" is to be performed,
        /// the following extension method can be used. Please note that performing such a query can easily become a performance hog; use it's power wisely!
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="searchKeys"></param>
        /// <param name="all"></param>
        /// <param name="fieldSelectors"></param>
        /// <example>
        /// The example below shows how you would generate a LINQ query that would execute the following in SQL:
        /// Select * from Table where (a.FirstName LIKE '%' + @p1 + '%' OR a.LastName LIKE '%' + @p2 +'%' OR a.NickName LIKE '%' + @p3 + '%') OR (a.FirstName LIKE '%' + @p4 + '%' OR a.LastName LIKE '%' + @p5 + '%' OR a.NickName LIKE '%' + @p6 + '%')
        /// </example>
        /// <code>
        /// var manyParam = new string[] { "Jody", "Jane" };
        /// var qry = dbContext.Table.MultiValueContainsAnyAll(manyParams, false, x => new [] { x.FirstName, x.LastName, x.NickName }).ToList();
        /// </code>
        /// <returns></returns>
        public static IQueryable <T> MultiValueContainsAnyAll <T>(this IQueryable <T> source,
                                                                  ICollection <string> searchKeys, bool all, Expression <Func <T, string[]> > fieldSelectors)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (fieldSelectors == null)
            {
                throw new ArgumentNullException(nameof(fieldSelectors));
            }
            var newArray = fieldSelectors.Body as NewArrayExpression;

            if (newArray == null)
            {
                throw new ArgumentOutOfRangeException(nameof(fieldSelectors), fieldSelectors,
                                                      "You need to use fieldSelectors similar to 'x => new string [] { x.LastName, x.FirstName, x.NickName }'; other forms not handled.");
            }
            if (newArray.Expressions.Count == 0)
            {
                throw new ArgumentException("No field selected.");
            }
            if (searchKeys == null || searchKeys.Count == 0)
            {
                return(source);
            }

            var        containsMethod = typeof(string).GetMethod("Contains", new Type[] { typeof(string) });
            Expression expression     = null;

            foreach (var searchKeyPart in searchKeys)
            {
                var        tmp = new Tuple <string>(searchKeyPart);
                Expression searchKeyExpression =
                    Expression.Property(Expression.Constant(tmp), tmp.GetType().GetProperty("Item1"));

                Expression oneValueExpression = null;
                foreach (var fieldSelector in newArray.Expressions)
                {
                    Expression act = Expression.Call(fieldSelector, containsMethod, searchKeyExpression);
                    oneValueExpression = oneValueExpression == null ? act : Expression.OrElse(oneValueExpression, act);
                }

                if (expression == null)
                {
                    expression = oneValueExpression;
                }
                else if (all)
                {
                    expression = Expression.AndAlso(expression, oneValueExpression);
                }
                else
                {
                    expression = Expression.OrElse(expression, oneValueExpression);
                }
            }
            return(source.Where(Expression.Lambda <Func <T, bool> >(expression, fieldSelectors.Parameters)));
        }
Exemplo n.º 12
0
        public void TupleCollection1()
        {
            var value        = new Tuple <Int32> (1);
            var data         = "0a0101";
            var encodeResult = Encoder.Encode(value, value.GetType());

            Assert.AreEqual(data, Hexlify(encodeResult));
            Tuple <Int32> decodeResult = (Tuple <Int32>)Encoder.Decode(Unhexlify(data), value.GetType(), null);

            Assert.AreEqual(value, decodeResult);
        }
Exemplo n.º 13
0
        public void TupleCollection2()
        {
            var          value        = new Tuple <int, string, bool> (1, "jeb", false);
            const string data         = "0a01010a04036a65620a0100";
            var          encodeResult = Encoder.Encode(value, value.GetType());

            Assert.AreEqual(data, encodeResult.ToHexString());
            var decodeResult = (Tuple <int, string, bool>)Encoder.Decode(data.ToByteString(), value.GetType(), null);

            Assert.AreEqual(value, decodeResult);
        }
Exemplo n.º 14
0
        public void TupleCollection2()
        {
            var value        = new Tuple <Int32, String, Boolean> (1, "jeb", false);
            var data         = "0a01010a04036a65620a0100";
            var encodeResult = Encoder.Encode(value, value.GetType());

            Assert.AreEqual(data, Hexlify(encodeResult));
            Tuple <Int32, String, Boolean> decodeResult = (Tuple <Int32, String, Boolean>)Encoder.Decode(Unhexlify(data), value.GetType(), null);

            Assert.AreEqual(value, decodeResult);
        }
Exemplo n.º 15
0
        public void WriteField(Writer writer, SerializerSession session, uint fieldIdDelta, Type expectedType, Tuple <T> value)
        {
            if (ReferenceCodec.TryWriteReferenceField(writer, session, fieldIdDelta, expectedType, value))
            {
                return;
            }
            writer.WriteFieldHeader(session, fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            this.valueCodec.WriteField(writer, session, 0, typeof(T), value.Item1);

            writer.WriteEndObject();
        }
Exemplo n.º 16
0
        void IFieldCodec <Tuple <T> > .WriteField <TBufferWriter>(ref Writer <TBufferWriter> writer, uint fieldIdDelta, Type expectedType, Tuple <T> value)
        {
            if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, value))
            {
                return;
            }
            writer.WriteFieldHeader(fieldIdDelta, expectedType, value.GetType(), WireType.TagDelimited);

            this.valueCodec.WriteField(ref writer, 0, typeof(T), value.Item1);

            writer.WriteEndObject();
        }
Exemplo n.º 17
0
        public void TestGetTypeName()
        {
            List <List <DateTime> > t = new List <List <DateTime> >();
            var s = t.GetType().GetTypeName();

            Assert.Equal("System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.DateTime]]", s);

            Tuple <int, List <string> > t1 = new Tuple <int, List <string> >(0, null);
            var name = t1.GetType().GetTypeName();

            Assert.Equal("System.Tuple`2[System.Int32,System.Collections.Generic.List`1[System.String]]", name);
        }
Exemplo n.º 18
0
        public void Dequeue_Test_Tuple()
        {
            Tuple <string, string> t = new Tuple <string, string>("naz1", "naz");
            Queue q = new Queue();

            q.Enqueue(t);
            Pomocne_funkcijeCreate pfc = new Pomocne_funkcijeCreate(mtf, qf);
            var s = pfc.Dequeue(q);

            Assert.AreEqual(s.GetType(), t.GetType());
            Assert.AreEqual(s, t);
        }
        public void DirectNormalTupleTest()
        {
            var model = new Tuple <int>(1);
            var v     = ObjectVisitor.Create(model.GetType(), model);

            v.ShouldNotBeNull();

            v["Item1"].ShouldBe(1);

            v["Item1"] = 100;

            v["Item1"].ShouldBe(1);
        }
Exemplo n.º 20
0
        public void DynamicCreateLongTypedTuple()
        {
            object tup = Tupler.Create(1, "2", "3", 4,
                    5, 6, 7, "8", "9", 10, "11", 12);

            var tup2 = new Tuple<int, string, string, int, int, int, int, Tuple<string, string, int, string, int>>(
                1, "2", "3", 4,
                5, 6, 7, Tuple.Create("8", "9", 10, "11", 12)
                );

            Assert.That(tup, Is.TypeOf(tup2.GetType()));

            Assert.That(tup, Is.EqualTo(tup2));
        }
Exemplo n.º 21
0
        public void DynamicCreateLongTypedTuple()
        {
            object tup = Tupler.Create(1, "2", "3", 4,
                                       5, 6, 7, "8", "9", 10, "11", 12);

            var tup2 = new Tuple <int, string, string, int, int, int, int, Tuple <string, string, int, string, int> >(
                1, "2", "3", 4,
                5, 6, 7, Tuple.Create("8", "9", 10, "11", 12)
                );

            Assert.That(tup, Is.TypeOf(tup2.GetType()));

            Assert.That(tup, Is.EqualTo(tup2));
        }
        public void TupleKeyInfoHelper_KeyMemberSelectorLarge()
        {
            var tuple = new Tuple <int, int, int, int, int, int, int, Tuple <int, int> >(
                1, 2, 3, 4, 5, 6, 7, new Tuple <int, int>(8, 9));

            TupleKeyInfoHelper builder = new TupleKeyInfoHelper(tuple.GetType());

            Expression source   = Expression.Constant(tuple);
            Expression selector = builder.CreateKeyMemberSelectorExpression(source, 7);

            int result = (int)Expression.Lambda(selector).Compile().DynamicInvoke();

            Assert.AreEqual(8, result);
        }
Exemplo n.º 23
0
        public void Create_InfersType( )
        {
            var          t1 = new Object( );
            const int    t2 = 5;
            const string t3 = "Hello";
            Tuple <int, string, Tuple <int, int> > t4 = Tuple.Create(4, "test", Tuple.Create(5, 1));

            Tuple <object, int, string, Tuple <int, string, Tuple <int, int> > > tuple4 = Tuple.Create(t1, t2, t3, t4);

            Assert.IsAssignableFrom(t1.GetType( ), tuple4.First);
            Assert.IsAssignableFrom(t2.GetType( ), tuple4.Second);
            Assert.IsAssignableFrom(t3.GetType( ), tuple4.Third);
            Assert.IsAssignableFrom(t4.GetType( ), tuple4.Fourth);
        }
Exemplo n.º 24
0
        public void Tuples()
        {
            (string a, int b, object c)a =
                (a : "a", b : 1, c : new { d = 2.71828 });
            var b = a.a;
            var c = foo(a);

            a = c;
            var t = new Tuple <int>(1);

            Assert.IsTrue(a.GetType().IsValueType);
            Assert.IsTrue(t.GetType().IsClass);
            (string a, int b, object notC)d = c;
            (string x, string y)            = AbMethod();
        }
Exemplo n.º 25
0
        private static Tuple CopyTuple(object[] newData, Tuple oldTuple)
        {
            Tuple res = (Tuple)Activator.CreateInstance(oldTuple.GetType());

            for (int i = 0; i < oldTuple.Capacity; i++)
            {
                ITemplatedValue itv = oldTuple.GetValue(i) as ITemplatedValue;
                if (itv == null)
                {
                    res.SetValue(i, res.GetValue(i));
                }

                res.SetValue(i, itv.CopyWithNewValue(newData[i]));
            }
            return(res);
        }
Exemplo n.º 26
0
        public Tuple <T> DeepCopy(Tuple <T> input, CopyContext context)
        {
            if (context.TryGetCopy(input, out Tuple <T> result))
            {
                return(result);
            }

            if (input.GetType() != typeof(Tuple <T>))
            {
                return(context.Copy(input));
            }

            result = new Tuple <T>(_copier.DeepCopy(input.Item1, context));
            context.RecordCopy(input, result);
            return(result);
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Tuple <int, DateTime> mydata = new Tuple <int, DateTime> (1, DateTime.Now);

            (int, string)somedata = (1, "Hello");

            var vardata = (1, "Hello");
            var vardb   = (roll : 1, sex : "m", age : 3, msg : "hello", asof : DateTime.Now);

            var pt1 = (X : 3, Y : 0);
            var pt2 = (X : 3, Y : 4);

            var xCoords = (pt1.X, pt2.X);


            var left  = (1, 5);
            var right = (1, 5);

            Console.WriteLine(left == right);

            Console.WriteLine(mydata.ToString());
            Console.WriteLine(somedata.ToString());
            Console.WriteLine(vardata.ToString());

            Console.WriteLine(mydata.GetType());
            Console.WriteLine(somedata.GetType());
            Console.WriteLine(vardata.GetType());



            int    x = default;
            string y = default;
            bool   z = default;

            Console.WriteLine(x);
            Console.WriteLine(y);
            Console.WriteLine(z);



            Console.WriteLine("Hello World!");
        }
Exemplo n.º 28
0
        public static void Main(string[] args)
        {
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201408/20140809/linq-jvm
            // X:\jsc.svn\examples\java\Test\TestNewArrayGenericImport\TestNewArrayGenericImport\Class1.cs


            // X:\jsc.svn\examples\java\Test\TestLocalGenericArgumentReference\TestLocalGenericArgumentReference\Class1.cs

            System.Console.WriteLine(
   typeof(object).AssemblyQualifiedName
);


            var z = new Tuple<MemberInfo, int>[] {
                // Tuple.Create(item.m, index)
            };

            Console.WriteLine(z.GetType().FullName);

            CLRProgram.CLRMain();
        }
Exemplo n.º 29
0
        public static void Main(string[] args)
        {
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201408/20140809/linq-jvm
            // X:\jsc.svn\examples\java\Test\TestNewArrayGenericImport\TestNewArrayGenericImport\Class1.cs


            // X:\jsc.svn\examples\java\Test\TestLocalGenericArgumentReference\TestLocalGenericArgumentReference\Class1.cs

            System.Console.WriteLine(
                typeof(object).AssemblyQualifiedName
                );


            var z = new Tuple <MemberInfo, int>[] {
                // Tuple.Create(item.m, index)
            };

            Console.WriteLine(z.GetType().FullName);

            CLRProgram.CLRMain();
        }
Exemplo n.º 30
0
            public void Test()
            {
                AssertEx.ThrowsException <ArgumentNullException>(() => base.Apply(expression: null), ex => Assert.AreEqual("expression", ex.ParamName));

                var prop = (PropertyInfo)ReflectionHelpers.InfoOf(() => DateTime.Now);

                AssertEx.ThrowsException <ArgumentNullException>(() => base.ResolveProperty(originalProperty: null, typeof(int), typeof(int), new[] { typeof(int) }), ex => Assert.AreEqual("originalProperty", ex.ParamName));
                AssertEx.ThrowsException <ArgumentNullException>(() => base.ResolveProperty(prop, declaringType: null, typeof(int), new[] { typeof(int) }), ex => Assert.AreEqual("declaringType", ex.ParamName));
                AssertEx.ThrowsException <ArgumentNullException>(() => base.ResolveProperty(prop, typeof(int), propertyType: null, new[] { typeof(int) }), ex => Assert.AreEqual("propertyType", ex.ParamName));

                var anon1 = new { a = 1 };
                var anon2 = new { a = 1, b = 2 };
                var atyp1 = (StructuralDataType)DataType.FromType(anon1.GetType());
                var atyp2 = (StructuralDataType)DataType.FromType(anon2.GetType());

                Assert.ThrowsException <InvalidOperationException>(() => base.ConvertConstantStructuralAnonymous(anon1, atyp1, atyp2));

                var tupl1 = new Tuple <int>(1);
                var tupl2 = new Tuple <int, int>(1, 2);
                var ttyp1 = (StructuralDataType)DataType.FromType(tupl1.GetType());
                var ttyp2 = (StructuralDataType)DataType.FromType(tupl2.GetType());

                Assert.ThrowsException <InvalidOperationException>(() => base.ConvertConstantStructuralTuple(tupl1, ttyp1, ttyp2));

                var rcrt1 = RuntimeCompiler.CreateRecordType(new[] { new KeyValuePair <string, Type>("a", typeof(int)) }, valueEquality: true);
                var rcrt2 = RuntimeCompiler.CreateRecordType(new[] { new KeyValuePair <string, Type>("a", typeof(int)), new KeyValuePair <string, Type>("b", typeof(int)) }, valueEquality: true);
                var rtyp1 = (StructuralDataType)DataType.FromType(rcrt1);
                var rtyp2 = (StructuralDataType)DataType.FromType(rcrt2);
                var rcrd1 = Activator.CreateInstance(rcrt1);

                Assert.ThrowsException <InvalidOperationException>(() => base.ConvertConstantStructuralRecord(rcrd1, rtyp1, rtyp2));

                var func1 = new Func <int>(() => 1);
                var func2 = new Func <int, int>(x => x);
                var ftyp1 = (FunctionDataType)DataType.FromType(func1.GetType());
                var ftyp2 = (FunctionDataType)DataType.FromType(func2.GetType());

                Assert.ThrowsException <InvalidOperationException>(() => base.ConvertConstantFunction(func1, ftyp1, ftyp2));
            }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            object o1 = 3, o2 = 4, ores;
            string s1 = "Hello"; long l1 = 3;

            try
            {
                ores = greater.of(o1, o2);
                var res = greater.of(s1, l1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            int    ires = greater.of(1, 2);
            string sres = greater.of("A", "B");

            Console.WriteLine(ires);

            Tuple <int, int, string> t3 = new Tuple <int, int, string>(2, 2, "444");

            Console.WriteLine(ExpandedTypeName(t3.GetType()));
        }
 public void Sit(
     string message,
     int howManyTimes,
     byte[] whatEvenIs                    = null,
     Guid[][] whatEvenIsThis              = null,
     T1[][][] whatEvenIsThisT             = null,
     List <byte[][]> evenMoreWhatIsThis   = null,
     List <DogTrick <T1> > previousTricks = null,
     Tuple <int, T1, string, object, Tuple <Tuple <T2, long>, long>, Task, Guid> tuple = null,
     Dictionary <int, IList <Task <DogTrick <T1> > > > whatAmIDoing = null)
 {
     for (var i = 0; i < howManyTimes; i++)
     {
         message +=
             message
             + whatEvenIs?.ToString()
             + whatEvenIsThis?.ToString()
             + whatEvenIsThisT?.ToString()
             + evenMoreWhatIsThis?.GetType()
             + previousTricks?.GetType()
             + tuple?.GetType()
             + whatAmIDoing?.GetType();
     }
 }
Exemplo n.º 33
0
 public void TupleCollection2()
 {
     var value = new Tuple<Int32,String,Boolean> (1, "jeb", false);
     var data = "0a01010a04036a65620a0100";
     var encodeResult = Encoder.Encode (value, value.GetType ());
     Assert.AreEqual (data, Hexlify (encodeResult));
     Tuple<Int32,String,Boolean> decodeResult = (Tuple<Int32,String,Boolean>)Encoder.Decode (Unhexlify (data), value.GetType (), null);
     Assert.AreEqual (value, decodeResult);
 }
Exemplo n.º 34
0
 public void TupleCollection1()
 {
     var value = new Tuple<Int32> (1);
     var data = "0a0101";
     var encodeResult = Encoder.Encode (value, value.GetType ());
     Assert.AreEqual (data, Hexlify (encodeResult));
     Tuple<Int32> decodeResult = (Tuple<Int32>)Encoder.Decode (Unhexlify (data), value.GetType (), null);
     Assert.AreEqual (value, decodeResult);
 }
        public void TupleKeyInfoHelper_KeyMemberSelectorLarge2()
        {
            var tuple = 
                new Tuple<int, int, int, int, int, int, int, 
                    Tuple<int, int, int, int, int, int, int, 
                        Tuple<int, int>>>(
                1, 2, 3, 4, 5, 6, 7, 
                    new Tuple<int, int, int, int, int, int, int, Tuple<int, int>>(
                        8, 9, 10, 11, 12, 13, 14, Tuple.Create(15, 16)));

            TupleKeyInfoHelper builder = new TupleKeyInfoHelper(tuple.GetType());

            Expression source = Expression.Constant(tuple);
            Expression selector = builder.CreateKeyMemberSelectorExpression(source, 15);

            int result = (int)Expression.Lambda(selector).Compile().DynamicInvoke();

            Assert.AreEqual(16, result);
        }
 private static int MethodCallTestMethod(int arg)
 {
     var a = new Tuple<int, int>(arg, -arg);
     return a.GetType().GetHashCode();
 }
Exemplo n.º 37
0
 public void TupleCollection1 ()
 {
     var value = new Tuple<int> (1);
     const string data = "0a0101";
     var encodeResult = Encoder.Encode (value, value.GetType ());
     Assert.AreEqual (data, encodeResult.ToHexString ());
     var decodeResult = (Tuple<int>)Encoder.Decode (data.ToByteString (), value.GetType (), null);
     Assert.AreEqual (value, decodeResult);
 }
Exemplo n.º 38
0
 public void TupleCollection2 ()
 {
     var value = new Tuple<int,string,bool> (1, "jeb", false);
     const string data = "0a01010a04036a65620a0100";
     var encodeResult = Encoder.Encode (value, value.GetType ());
     Assert.AreEqual (data, encodeResult.ToHexString ());
     var decodeResult = (Tuple<int,string,bool>)Encoder.Decode (data.ToByteString (), value.GetType (), null);
     Assert.AreEqual (value, decodeResult);
 }