public void NonGenericMethod_FromGenericClass()
        {
            var m = DelegateFactory.InstanceMethod <Func <GenericClass <TestClass>, TestClass, TestClass> >("InstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_genericClassInstance, _testClassInstance);

            Assert.AreEqual(_testClassInstance, result);
        }
        public void Public_GenericMethod_Void_NoParameter_OneTypeParameter_ByObjectAndTypes_WithCast()
        {
            var m = _testClassType.InstanceMethod <Action <object>, string>("PublicInstanceGenericMethodVoid");

            Assert.IsNotNull(m);
            m(_testClassInstance);
            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.AreEqual(typeof(string), _testClassInstance.PublicTypeParams[0]);
        }
        public void IndexerSet_ByObjects_4Index_FromStruct()
        {
            var @is = _testStrucType.IndexerSetStruct(typeof(int), typeof(int), typeof(int), typeof(int), typeof(int));

            Assert.IsNotNull(@is);
            var objectStruct = (object)_testStructInstance;

            @is(ref objectStruct, new object[] { FirstIntIndex, SecondIntIndex, 0, 0 }, NewIntValue);
            Assert.AreEqual(NewIntValue, ((TestStruct)objectStruct).Public4IndexIndexer);
        }
Beispiel #4
0
        public void PropertySet_ByObjects_Public_Struct_FromStructRef()
        {
            var ps = _testStrucType.PropertySetStructRef("PublicPropertyInt");

            Assert.IsNotNull(ps);
            var objectStruct = (object)_testStructInstance;

            ps(ref objectStruct, NewIntValue);
            Assert.AreEqual(NewIntValue, ((TestStruct)objectStruct).PublicPropertyInt);
        }
Beispiel #5
0
        public void FieldSet_ByObjects_Public_Struct_FromStructRef()
        {
            var fs = _testStructType.FieldSetStructRef("PublicFieldInt");

            Assert.IsNotNull(fs);
            var objectStruct = (object)_testStructInstance;

            fs(ref objectStruct, NewIntValue);
            Assert.AreEqual(NewIntValue, ((TestStruct)objectStruct).PublicFieldInt);
        }
Beispiel #6
0
        public void PropertySet_ByExtensionAndReturnType_Private_FromStructRef()
        {
            var ps = _testStrucType.PropertySetStructRef <string>("PrivateProperty");

            Assert.IsNotNull(ps);
            var objectStruct = (object)_testStructInstance;

            ps(ref objectStruct, NewStringValue);
            Assert.AreEqual(NewStringValue, ((TestStruct)objectStruct).GetPrivateProperty());
        }
        public void IndexerSet_ByExtensionAndReturnType_Internal_FromStruct()
        {
            var @is = _testStrucType.IndexerSetStruct <double, double>();

            Assert.IsNotNull(@is);
            var objectStruct = (object)_testStructInstance;

            @is(ref objectStruct, FirstDoubleIndex, NewDoubleValue);
            Assert.AreEqual(NewDoubleValue, ((TestStruct)objectStruct).InternalIndexer);
        }
        public void IndexerSet_ByObjects_Public_FromStruct()
        {
            var @is = _testStrucType.IndexerSetStruct(typeof(int), typeof(int));

            Assert.IsNotNull(@is);
            var objectStruct = (object)_testStructInstance;

            @is(ref objectStruct, new object[] { FirstIntIndex }, NewIntValue);
            Assert.AreEqual(NewIntValue, ((TestStruct)objectStruct).IndexerBackend[FirstIntIndex]);
        }
        public void IndexerSet_ByExtensionAndReturnType_3Index_FromStruct()
        {
            var @is = _testStrucType.IndexerSetStruct <int, int, int, int>();

            Assert.IsNotNull(@is);
            var objectStruct = (object)_testStructInstance;

            @is(ref objectStruct, FirstIntIndex, SecondIntIndex, 0, NewIntValue);
            Assert.AreEqual(NewIntValue, ((TestStruct)objectStruct).Public3IndexIndexer);
        }
Beispiel #10
0
        public void FieldSet_ByObjects_Internal_FromStructRef()
        {
            var fs = _testStructType.FieldSetStructRef("InternalField");

            Assert.IsNotNull(fs);
            var objectStruct = (object)_testStructInstance;

            fs(ref objectStruct, NewStringValue);
            Assert.AreEqual(NewStringValue, ((TestStruct)objectStruct).InternalField);
        }
        public void IndexerSet_ByObjects_Internal_FromStruct()
        {
            var @is = _testStrucType.IndexerSetStruct(typeof(double), typeof(double));

            Assert.IsNotNull(@is);
            var objectStruct = (object)_testStructInstance;

            @is(ref objectStruct, new object[] { FirstDoubleIndex }, NewDoubleValue);
            Assert.AreEqual(NewDoubleValue, ((TestStruct)objectStruct).InternalIndexer);
        }
        public void Protected_GenericMethod_Void_NoParameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.InstanceGenericMethodVoid("ProtectedInstanceGenericMethodVoid", null,
                                                             new[] { typeof(string) });

            Assert.IsNotNull(m);
            m(_testClassInstance, new object[0]);
            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.AreEqual(typeof(string), _testClassInstance.PublicTypeParams[0]);
        }
Beispiel #13
0
        public void PropertySet_ByObjects_Internal_FromStructRef()
        {
            var ps = _testStrucType.PropertySetStructRef("InternalProperty");

            Assert.IsNotNull(ps);
            var objectStruct = (object)_testStructInstance;

            ps(ref objectStruct, NewStringValue);
            Assert.AreEqual(NewStringValue, ((TestStruct)objectStruct).InternalProperty);
        }
Beispiel #14
0
        public void Private_GenericMethod_Void_NoParameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.StaticGenericMethodVoid("PrivateStaticGenericMethodVoid", null,
                                                           new[] { typeof(string) });

            Assert.IsNotNull(m);
            m(new object[0]);
            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.AreEqual(typeof(string), TestClass.StaticPublicTypeParams[0]);
        }
Beispiel #15
0
        public void FieldSet_ByExtensionAndReturnType_Private_FromStructRef()
        {
            var fs = _testStructType.FieldSetStructRef <string>("_privateField");

            Assert.IsNotNull(fs);
            var objectStruct = (object)_testStructInstance;

            fs(ref objectStruct, NewStringValue);
            Assert.AreEqual(NewStringValue, ((TestStruct)objectStruct).GetPrivateField());
        }
Beispiel #16
0
        public void Private_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjectAndTypes()
        {
            var m = _testClassType.StaticMethod <Func <TestClass>, TestClass>("PrivateStaticGenericMethod");

            Assert.IsNotNull(m);
            var result = m();

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
        public void Public_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByTypes()
        {
            var m = DelegateFactory.InstanceMethod <Func <TestClass, TestClass>, TestClass>("PublicInstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance);

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
        public void Private_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjectAndTypes_WithCast()
        {
            var m = _testClassType.InstanceMethod <Func <object, TestClass>, TestClass>("PrivateInstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance);

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
Beispiel #19
0
        public void Internal_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByTypes()
        {
            var m = DelegateFactory.StaticMethod <TestClass, Func <TestClass>, TestClass>("InternalStaticGenericMethod");

            Assert.IsNotNull(m);
            var result = m();

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
Beispiel #20
0
        public void GenericMethod_NoVoid_SingleParameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.StaticGenericMethod("StaticGenericMethod", new[] { _testClassType },
                                                       new[] { _testClassType });
            var result = m(new object[] { _testClassInstance });

            Assert.AreEqual(1, TestClass.StaticPublicParams.Length);
            Assert.AreEqual(_testClassInstance, TestClass.StaticPublicParams[0]);
            Assert.AreEqual(_testClassInstance, result);
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
        public void GenericMethod_NoVoid_SingleParameter_OneTypeParameter_ByObjectAndTypes_WithCast()
        {
            var m = _testClassType.InstanceMethod <Func <object, TestClass, TestClass>, TestClass>("InstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance, _testClassInstance);

            Assert.AreEqual(1, _testClassInstance.PublicParams.Length);
            Assert.AreEqual(_testClassInstance, _testClassInstance.PublicParams[0]);
            Assert.AreEqual(_testClassInstance, result);
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
        public void Protected_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.InstanceGenericMethod("ProtectedInstanceGenericMethod", null,
                                                         new[] { _testClassType });

            Assert.IsNotNull(m);
            var result = m(_testClassInstance, new object[] { _testClassInstance });

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
Beispiel #23
0
        public void Private_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.StaticGenericMethod("PrivateStaticGenericMethod", null,
                                                       new[] { _testClassType });

            Assert.IsNotNull(m);
            var result = m(new object[] { });

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
Beispiel #24
0
        public void GenericMethod_NoVoid_SingleParameter_OneTypeParameter_ByObjectAndTypes()
        {
            var m = _testClassType.StaticMethod <Func <TestClass, TestClass>, TestClass>("StaticGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance);

            Assert.AreEqual(1, TestClass.StaticPublicParams.Length);
            Assert.AreEqual(_testClassInstance, TestClass.StaticPublicParams[0]);
            Assert.AreEqual(_testClassInstance, result);
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
        public void GenericMethod_NoVoid_NoParameter_2TypeParameters_ByObjectAndTypes()
        {
            var m = _testClassType.InstanceMethod <Func <TestClass, TestClass>, TestClass, TestStruct>
                        ("InstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance);

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
            Assert.AreEqual(typeof(TestStruct), _testClassInstance.PublicTypeParams[1]);
        }
Beispiel #26
0
        public void GenericMethod_NoVoid_NoParameter_2TypeParameters_ByObjects()
        {
            var m = _testClassType.StaticGenericMethod("StaticGenericMethod", null,
                                                       new[] { _testClassType, _testStructType });

            Assert.IsNotNull(m);
            var result = m(new object[0]);

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
            Assert.AreEqual(typeof(TestStruct), TestClass.StaticPublicTypeParams[1]);
        }
Beispiel #27
0
        public void GenericMethod_NoVoid_2Parameter_OneTypeParameter_ByTypes()
        {
            var m = DelegateFactory.StaticMethod <TestClass, Func <TestClass, int, TestClass>, TestClass>
                        ("StaticGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance, 0);

            Assert.AreEqual(2, TestClass.StaticPublicParams.Length);
            Assert.AreEqual(_testClassInstance, TestClass.StaticPublicParams[0]);
            Assert.AreEqual(_testClassInstance, result);
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
        public void GenericMethod_NoVoid_SingleParameter_OneTypeParameter_ByTypes()
        {
            var m = DelegateFactory.InstanceMethod <Func <TestClass, TestClass, TestClass>, TestClass>
                        ("InstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance, _testClassInstance);

            Assert.AreEqual(1, _testClassInstance.PublicParams.Length);
            Assert.AreEqual(_testClassInstance, _testClassInstance.PublicParams[0]);
            Assert.AreEqual(_testClassInstance, result);
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
        public void GenericMethod_NoVoid_2Parameter_OneTypeParameter_ByObjectAndTypes()
        {
            var m = _testClassType.InstanceMethod <Func <TestClass, TestClass, int, TestClass>, TestClass>
                        ("InstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance, _testClassInstance, 0);

            Assert.AreEqual(2, _testClassInstance.PublicParams.Length);
            Assert.AreEqual(_testClassInstance, _testClassInstance.PublicParams[0]);
            Assert.AreEqual(0, _testClassInstance.PublicParams[1]);
            Assert.AreEqual(_testClassInstance, result);
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
Beispiel #30
0
        public void GenericMethod_NoVoid_2Parameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.StaticGenericMethod("StaticGenericMethod", new[] { _testClassType, typeof(int) },
                                                       new[] { _testClassType });

            Assert.IsNotNull(m);
            var result = m(new object[] { _testClassInstance, 0 });

            Assert.AreEqual(2, TestClass.StaticPublicParams.Length);
            Assert.AreEqual(_testClassInstance, TestClass.StaticPublicParams[0]);
            Assert.AreEqual(0, TestClass.StaticPublicParams[1]);
            Assert.AreEqual(_testClassInstance, result);
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }