コード例 #1
0
        public void NegTest1()
        {
            DynamicMethod            testDynMethod;
            TestCreateDelegateOwner2 target = new TestCreateDelegateOwner2();

            testDynMethod = this.CreateDynMethod(_DYNAMIC_METHOD_OWNER_TYPE);
            Assert.Throws <InvalidOperationException>(() =>
            {
                UseLikeStatic2 staticCallBack = (UseLikeStatic2)testDynMethod.CreateDelegate(typeof(UseLikeStatic2));
            });
        }
コード例 #2
0
        public void NegTest4()
        {
            DynamicMethod            testDynMethod;
            FieldInfo                fieldInfo;
            TestCreateDelegateOwner2 target = new TestCreateDelegateOwner2();

            fieldInfo = _DYNAMIC_METHOD_OWNER_TYPE.GetField(
                c_FIELD_NAME,
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            testDynMethod = this.CreateDynMethod(_DYNAMIC_METHOD_OWNER_TYPE);
            this.EmitDynMethodBody(testDynMethod, fieldInfo);
            Assert.Throws <ArgumentException>(() =>
            {
                InvalidParamType2 invalidCallBack = (InvalidParamType2)testDynMethod.CreateDelegate(typeof(InvalidParamType2));
            });
        }
コード例 #3
0
        public void PosTest3()
        {
            DynamicMethod testDynMethod;
            FieldInfo fieldInfo;
            TestCreateDelegateOwner2 target = new TestCreateDelegateOwner2();
            int newId = 100;

            bool actualResult;
            fieldInfo = _DYNAMIC_METHOD_OWNER_TYPE.GetField(
                                c_FIELD_NAME,
                                BindingFlags.NonPublic |
                                BindingFlags.Instance);

            testDynMethod = this.CreateDynMethod(this.CurrentModule);
            this.EmitDynMethodBody(testDynMethod, fieldInfo);

            UseLikeStatic2 staticCallBack = (UseLikeStatic2)testDynMethod.CreateDelegate(typeof(UseLikeStatic2));
            actualResult = target.ID == staticCallBack(target, newId);
            actualResult = (target.ID == newId) && actualResult;

            Assert.True(actualResult, "Failed to create delegate for dynamic method.");
        }
コード例 #4
0
        public void PosTest1()
        {
            DynamicMethod            testDynMethod;
            FieldInfo                fieldInfo;
            TestCreateDelegateOwner2 target = new TestCreateDelegateOwner2();
            int newId = 100;

            bool actualResult;

            fieldInfo = _DYNAMIC_METHOD_OWNER_TYPE.GetField(
                c_FIELD_NAME,
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            testDynMethod = this.CreateDynMethod(_DYNAMIC_METHOD_OWNER_TYPE);
            this.EmitDynMethodBody(testDynMethod, fieldInfo);

            UseLikeStatic2 staticCallBack = (UseLikeStatic2)testDynMethod.CreateDelegate(typeof(UseLikeStatic2));

            actualResult = target.ID == staticCallBack(target, newId);
            actualResult = (target.ID == newId) && actualResult;
            Assert.True(actualResult, "Failed to create delegate for dynamic method.");
        }
コード例 #5
0
        public void NegTest4()
        {
            DynamicMethod testDynMethod;
            FieldInfo fieldInfo;
            TestCreateDelegateOwner2 target = new TestCreateDelegateOwner2();

            fieldInfo = _DYNAMIC_METHOD_OWNER_TYPE.GetField(
                                c_FIELD_NAME,
                                BindingFlags.NonPublic |
                                BindingFlags.Instance);

            testDynMethod = this.CreateDynMethod(_DYNAMIC_METHOD_OWNER_TYPE);
            this.EmitDynMethodBody(testDynMethod, fieldInfo);
            Assert.Throws<ArgumentException>(() =>
            {
                InvalidParamType2 invalidCallBack = (InvalidParamType2)testDynMethod.CreateDelegate(typeof(InvalidParamType2));
            });
        }
コード例 #6
0
        public void NegTest1()
        {
            DynamicMethod testDynMethod;
            TestCreateDelegateOwner2 target = new TestCreateDelegateOwner2();

            testDynMethod = this.CreateDynMethod(_DYNAMIC_METHOD_OWNER_TYPE);
            Assert.Throws<InvalidOperationException>(() =>
            {
                UseLikeStatic2 staticCallBack = (UseLikeStatic2)testDynMethod.CreateDelegate(typeof(UseLikeStatic2));
            });
        }