Ejemplo n.º 1
0
        static Getters()
        {
            testUri      = new TestUri("SomeHost");
            @class       = testUri.GetType();
            property     = @class.GetProperty(propertyName, bindingFlags);
            fastProperty = new FastProperty(property, bindingFlags);
            getgetMethod = property.GetGetMethod(nonPublic: allowNonPublicFieldAccess);

            // Using FastMember - https://github.com/mgravell/fast-member
            fastMember = TypeAccessor.Create(@class, allowNonPublicAccessors: allowNonPublicFieldAccess);

            Type funcType = Type.GetType("System.Func`2[Benchmark.TestUri, System.String]");

            getDelegate        = (Func <TestUri, string>)Delegate.CreateDelegate(funcType, getgetMethod);
            getDelegateDynamic = Delegate.CreateDelegate(funcType, getgetMethod);

            Emit <Func <TestUri, string> > getterEmiter = Emit <Func <TestUri, string> >
                                                          .NewDynamicMethod("GetTestUriProperty")
                                                          .LoadArgument(0)
                                                          .Call(getgetMethod)
                                                          .Return();

            funcTstring = getterEmiter.CreateDelegate();

            ffgetter = Reflect.PropertyGetter(property);

            Emit <Func <object, object> > objGetterEmiterFunc = Emit <Func <object, object> >
                                                                .NewDynamicMethod("GetMSTestUriProperty")
                                                                .LoadArgument(0)
                                                                .CastClass(typeof(TestUri))
                                                                .Call(getgetMethod)
                                                                .Return();

            funcObjObj = objGetterEmiterFunc.CreateDelegate();
        }
Ejemplo n.º 2
0
        static Setters()
        {
            testUri      = new TestUri("SomeHost");
            @class       = testUri.GetType();
            property     = @class.GetProperty(propertyName, bindingFlags);
            fastProperty = new FastProperty(property, bindingFlags);
            getsetMethod = property.GetSetMethod(nonPublic: allowNonPublicFieldAccess);
            fastMember   = TypeAccessor.Create(@class, allowNonPublicAccessors: allowNonPublicFieldAccess);

            Type actionType = Type.GetType("System.Action`2[Benchmark.TestUri, System.String]");

            setDelegate        = (Action <TestUri, string>)Delegate.CreateDelegate(actionType, getsetMethod);
            setDelegateDynamic = Delegate.CreateDelegate(actionType, getsetMethod);

            var setterEmiter = Emit <Action <TestUri, string> >
                               .NewDynamicMethod("SetTestUriProperty")
                               .LoadArgument(0)
                               .LoadArgument(1)
                               .Call(getsetMethod)
                               .Return();

            setter = setterEmiter.CreateDelegate();

            ffsetter = Reflect.PropertySetter(property);

            var objSetterEmiterAction = Emit <Action <object, object> >
                                        .NewDynamicMethod("SetObjTestUriProperty")
                                        .LoadArgument(0)
                                        .CastClass(typeof(TestUri))
                                        .LoadArgument(1)
                                        .CastClass(typeof(string))
                                        .Call(getsetMethod)
                                        .Return();

            objsetter = objSetterEmiterAction.CreateDelegate();
        }