当前位置: 首页>>代码示例>>C#>>正文


C# TypeBuilder.DefineMethodOverride方法代码示例

本文整理汇总了C#中System.Reflection.Emit.TypeBuilder.DefineMethodOverride方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.DefineMethodOverride方法的具体用法?C# TypeBuilder.DefineMethodOverride怎么用?C# TypeBuilder.DefineMethodOverride使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.TypeBuilder的用法示例。


在下文中一共展示了TypeBuilder.DefineMethodOverride方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImplementProxy

		public void ImplementProxy(TypeBuilder typeBuilder)
		{
			typeBuilder.AddInterfaceImplementation(typeof (IProxy));
			InterceptorField = typeBuilder
				.DefineField("__interceptor",
							 typeof (Proxy.DynamicProxy.IInterceptor),
							 FieldAttributes.Private);
			var getterMethod = typeBuilder
				.DefineMethod("get_Interceptor",
							  InterceptorMethodsAttributes,
							  CallingConventions.HasThis,
							  typeof (Proxy.DynamicProxy.IInterceptor),
							  new System.Type[0]);
			getterMethod.SetImplementationFlags(MethodImplAttributes.IL);
			var il = getterMethod.GetILGenerator();
			il.Emit(OpCodes.Ldarg_0);
			il.Emit(OpCodes.Ldfld, InterceptorField);
			il.Emit(OpCodes.Ret);
			var setterMethod = typeBuilder
				.DefineMethod("set_Interceptor",
							  InterceptorMethodsAttributes,
							  CallingConventions.HasThis,
							  typeof (void),
							  new[] {typeof (Proxy.DynamicProxy.IInterceptor)});
			setterMethod.SetImplementationFlags(MethodImplAttributes.IL);
			il = setterMethod.GetILGenerator();
			il.Emit(OpCodes.Ldarg_0);
			il.Emit(OpCodes.Ldarg_1);
			il.Emit(OpCodes.Stfld, InterceptorField);
			il.Emit(OpCodes.Ret);
			var originalSetter = typeof (IProxy).GetMethod("set_Interceptor");
			var originalGetter = typeof (IProxy).GetMethod("get_Interceptor");
			typeBuilder.DefineMethodOverride(setterMethod, originalSetter);
			typeBuilder.DefineMethodOverride(getterMethod, originalGetter);
		}
开发者ID:mynamespace,项目名称:NHibernate.Extensions,代码行数:35,代码来源:ProxyImplementor.cs

示例2: ImplementProxy

		public void ImplementProxy(TypeBuilder typeBuilder)
		{
			// Implement the IProxy interface
			typeBuilder.AddInterfaceImplementation(typeof (IProxy));

			field = typeBuilder.DefineField("__interceptor", typeof (IInterceptor), FieldAttributes.Private);

			// Implement the getter
			MethodBuilder getterMethod = typeBuilder.DefineMethod("get_Interceptor", InterceptorMethodsAttributes, CallingConventions.HasThis, typeof(IInterceptor), new System.Type[0]);
			getterMethod.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);

			ILGenerator IL = getterMethod.GetILGenerator();

			// This is equivalent to:
			// get { return __interceptor;
			IL.Emit(OpCodes.Ldarg_0);
			IL.Emit(OpCodes.Ldfld, field);
			IL.Emit(OpCodes.Ret);

			// Implement the setter
			MethodBuilder setterMethod = typeBuilder.DefineMethod("set_Interceptor", InterceptorMethodsAttributes, CallingConventions.HasThis, typeof (void), new[] {typeof (IInterceptor)});

			setterMethod.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);
			IL = setterMethod.GetILGenerator();
			IL.Emit(OpCodes.Ldarg_0);
			IL.Emit(OpCodes.Ldarg_1);
			IL.Emit(OpCodes.Stfld, field);
			IL.Emit(OpCodes.Ret);

			MethodInfo originalSetter = typeof (IProxy).GetMethod("set_Interceptor");
			MethodInfo originalGetter = typeof (IProxy).GetMethod("get_Interceptor");

			typeBuilder.DefineMethodOverride(setterMethod, originalSetter);
			typeBuilder.DefineMethodOverride(getterMethod, originalGetter);
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:35,代码来源:ProxyImplementor.cs

示例3: GenerateInvocation

        /// <summary>
        /// Creates a <see cref="MethodBuilder"/> and implements a default wrapper.
        /// </summary>
        /// <param name="owner">The type that will own this method.</param>
        /// <param name="interfaceType">Type of interface implemented by the <paramref name="owner"/>.</param>
        /// <param name="overrideMethod">Method to override.</param>
        /// <param name="fieldBuilders">Fields specified by the <see paramref="owner"/>.</param>
        /// <returns>MethodBuilder with an already implemented wrapper.</returns>
        public MethodBuilder GenerateInvocation(TypeBuilder owner, Type interfaceType, MethodInfo overrideMethod, IEnumerable<FieldBuilder> fieldBuilders)
        {
            var result = owner.DefineMethod
                    (
                        overrideMethod.Name,
                        MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final |
                        MethodAttributes.HideBySig | MethodAttributes.NewSlot,
                        overrideMethod.ReturnType,
                        overrideMethod.GetParameters().OrderBy(p => p.Position).Select(t => t.ParameterType).ToArray()
                    );

            result.SetImplementationFlags(MethodImplAttributes.AggressiveInlining);

            var generator = result.GetILGenerator();
            var fieldName = LibraryInterfaceMapper.GetFieldNameForMethodInfo(overrideMethod);
            var field = fieldBuilders.First(f => f.Name == fieldName);
            var parameters = overrideMethod.GetParameters();
            OnInvokeBegin(owner, interfaceType, generator, overrideMethod);
            generator.Emit(OpCodes.Ldarg_0); //  this
            generator.Emit(OpCodes.Ldfld, field); // MethodNameProc _glMethodName. Initialized by constructor.
            foreach (var item in parameters.Where(p => !p.IsRetval).Select((p, i) => new { Type = p, Index = i }))
            {
                generator.Emit(OpCodes.Ldarg, item.Index + 1);
            }

            generator.EmitCall(OpCodes.Callvirt, field.FieldType.GetMethod("Invoke"), null);

            OnInvokeEnd(owner, interfaceType, generator, overrideMethod);

            generator.Emit(OpCodes.Ret);

            owner.DefineMethodOverride(result, overrideMethod);

            return result;
        }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:43,代码来源:DefaultMethodCallWrapper.cs

示例4: ImplementAddInterceptionBehavior

        private static void ImplementAddInterceptionBehavior(TypeBuilder typeBuilder, FieldInfo proxyInterceptorPipelineField)
        {
            // Declaring method builder
            // Method attributes
            const MethodAttributes MethodAttributes = MethodAttributes.Private | MethodAttributes.Virtual
                | MethodAttributes.Final | MethodAttributes.HideBySig
                    | MethodAttributes.NewSlot;

            MethodBuilder methodBuilder =
                typeBuilder.DefineMethod(
                    "Microsoft.Practices.Unity.InterceptionExtension.IInterceptingProxy.AddInterceptionBehavior",
                    MethodAttributes);

            // Setting return type
            methodBuilder.SetReturnType(typeof(void));
            // Adding parameters
            methodBuilder.SetParameters(typeof(IInterceptionBehavior));
            // Parameter method
            methodBuilder.DefineParameter(1, ParameterAttributes.None, "interceptor");

            ILGenerator il = methodBuilder.GetILGenerator();
            // Writing body
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, proxyInterceptorPipelineField);
            il.Emit(OpCodes.Ldarg_1);
            il.EmitCall(OpCodes.Callvirt, InterceptionBehaviorPipelineMethods.Add, null);
            il.Emit(OpCodes.Ret);
            typeBuilder.DefineMethodOverride(methodBuilder, IInterceptingProxyMethods.AddInterceptionBehavior);
        }
开发者ID:kangkot,项目名称:unity,代码行数:29,代码来源:InterceptingProxyImplementor.cs

示例5: Generate

        public override MethodBuilder Generate(TypeBuilder typeBuilder)
        {
            var methodBuilder = GenerateMethod(typeBuilder);

            typeBuilder.DefineMethodOverride(methodBuilder, _methodMetadata.Method);

            return methodBuilder;
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:8,代码来源:DuckTypeMethodGenerator.cs

示例6: EmitOverride_GetCacheType

        private void EmitOverride_GetCacheType(TypeBuilder typeBuilder, string overrideName, FieldBuilder fb_cacheType)
        {
            MethodBuilder mb = typeBuilder.DefineMethod(overrideName, MethodAttributes.Family | MethodAttributes.Virtual);
            mb.SetReturnType(typeof(Type));
            typeBuilder.DefineMethodOverride(mb,
                typeof(ReadMapper).GetMethod(overrideName, BindingFlags.NonPublic | BindingFlags.Instance));

            ILGenerator il = mb.GetILGenerator();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, fb_cacheType);
            il.Emit(OpCodes.Ret);
        }
开发者ID:ExM,项目名称:OncRpc,代码行数:12,代码来源:ReadBuilder.EmitDynReadMapper.cs

示例7: ImplementProxy

 public void ImplementProxy(TypeBuilder b)
 {
     var dynamicProxyType = typeof(IDynamicProxy);
     b.AddInterfaceImplementation(dynamicProxyType);
     _fieldBuilder = b.DefineField("__interceptor", typeof(IMethodInterceptor), FieldAttributes.Private);
     const MethodAttributes attributes = MethodAttributes.SpecialName | MethodAttributes.VtableLayoutMask | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.Public;
     var getMethodBuilder = b.DefineMethod("get_Interceptor", attributes, CallingConventions.HasThis, typeof(IMethodInterceptor), new Type[0]);
     getMethodBuilder.SetImplementationFlags(MethodImplAttributes.IL);
     var w = getMethodBuilder.GetILGenerator();
     w.Emit(OpCodes.Ldarg_0);
     w.Emit(OpCodes.Ldfld, _fieldBuilder);
     w.Emit(OpCodes.Ret);
     var setMethodBuilder = b.DefineMethod("set_Interceptor", attributes, CallingConventions.HasThis, typeof(void), new Type[] { typeof(IMethodInterceptor) });
     setMethodBuilder.SetImplementationFlags(MethodImplAttributes.IL);
     w = setMethodBuilder.GetILGenerator();
     w.Emit(OpCodes.Ldarg_0);
     w.Emit(OpCodes.Ldarg_1);
     w.Emit(OpCodes.Stfld, _fieldBuilder);
     w.Emit(OpCodes.Ret);
     b.DefineMethodOverride(setMethodBuilder, dynamicProxyType.GetMethod("set_Interceptor"));
     b.DefineMethodOverride(getMethodBuilder, dynamicProxyType.GetMethod("get_Interceptor"));
 }
开发者ID:BclEx,项目名称:AdamsyncEx,代码行数:22,代码来源:DynamicProxyImplementor.cs

示例8: DefineMethod

            private static MethodBuilder DefineMethod(TypeBuilder newType, Type interfaceType, string methodName)
            {
                MethodInfo getInterfaceMethodInfo = interfaceType.GetMethod(methodName);
                MethodBuilder getMethod = newType.DefineMethod(
                    string.Concat(interfaceType.Name, '.', getInterfaceMethodInfo.Name),
                    MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Virtual,
                     CallingConventions.Standard,
                     getInterfaceMethodInfo.ReturnType,
                     ClassWrappers.GetParameterTypes(getInterfaceMethodInfo.GetParameters()));

                newType.DefineMethodOverride(getMethod, getInterfaceMethodInfo);
                return getMethod;
            }
开发者ID:guidgets,项目名称:DataAccessLayer,代码行数:13,代码来源:ClassWrappers.PropertyWrapperGenerator.cs

示例9: WriteIsAuthorized

        private static void WriteIsAuthorized(Type parentType, TypeBuilder builder)
        {
            MethodInfo protectedMethod = parentType.GetMethod("AuthorizeCore", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
            MethodBuilder implementedMethod = builder.DefineMethod("IsAuthorized", MethodAttributes.Public | MethodAttributes.Virtual, typeof(bool), new[] { typeof(HttpContextBase) });
            ILGenerator il = implementedMethod.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Call, protectedMethod);
            il.Emit(OpCodes.Ret);

            MethodInfo interfaceMethod = authorizeAttributeType.GetMethod("IsAuthorized", BindingFlags.Public | BindingFlags.Instance);
            builder.DefineMethodOverride(implementedMethod, interfaceMethod);
        }
开发者ID:hazzik,项目名称:telerikaspnetmvc,代码行数:14,代码来源:AuthorizeAttributeBuilder.cs

示例10: DefinePropertyGetMethod

            private static MethodBuilder DefinePropertyGetMethod(TypeBuilder newType, string propertyName, Type interfaceType)
            {
                MethodInfo getPropertyMethod = interfaceType.GetProperty(propertyName).GetGetMethod();

                if (getPropertyMethod == null)
                    return null;

                MethodBuilder builder = newType.DefineMethod(
                    string.Concat(interfaceType.Name, '.', getPropertyMethod.Name),
                    MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Virtual,
                    getPropertyMethod.ReturnType, Type.EmptyTypes);

                newType.DefineMethodOverride(builder, getPropertyMethod);

                return builder;
            }
开发者ID:guidgets,项目名称:DataAccessLayer,代码行数:16,代码来源:ClassWrappers.PropertyWrapperGenerator.cs

示例11: DefineMethod

            private static MethodBuilder DefineMethod(TypeBuilder newType, Type interfaceType, string methodName, Type[] parameterTypes)
            {
                MethodInfo getMethod = interfaceType.GetMethod(methodName, parameterTypes);

                if (getMethod == null)
                    return null;

                MethodBuilder builder = newType.DefineMethod(
                    string.Concat(interfaceType.Name, '.', getMethod.Name),
                    MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Virtual,
                    getMethod.ReturnType, parameterTypes);

                newType.DefineMethodOverride(builder, getMethod);

                return builder;
            }
开发者ID:guidgets,项目名称:DataAccessLayer,代码行数:16,代码来源:ClassWrappers.ClassWrapperGenerator.cs

示例12: BuildIProxyTargetPropertyMethod

        private static void BuildIProxyTargetPropertyMethod(
			TypeBuilder proxyBuilder, Type targetType, Type iProxyType,
			FieldBuilder wrappedObject, TypeDebugging debug)
        {
            var attributes = MethodAttributes.HideBySig |
                 MethodAttributes.Virtual | MethodAttributes.Private;
            var method = proxyBuilder.DefineMethod(GetTargetMethod,
                 attributes, targetType, Type.EmptyTypes);
            proxyBuilder.DefineMethodOverride(method,
                iProxyType.GetProperty(TargetProperty).GetGetMethod());

            using (var generator = debug.GetMethodDebugging(method))
            {
                generator.Emit(OpCodes.Ldarg_0);
                generator.Emit(OpCodes.Ldfld, wrappedObject);
                generator.Emit(OpCodes.Ret);
            }
        }
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:18,代码来源:ProxyMethodBuilder.cs

示例13: Implement

		public static void Implement (TypeBuilder typeB, Type iface)
		{
			typeB.AddInterfaceImplementation (iface);

			foreach (MethodInfo declMethod in iface.GetMethods ()) {

				MethodBuilder method_builder = typeB.DefineMethod (declMethod.Name, MethodAttributes.Public | MethodAttributes.Virtual, declMethod.ReturnType, Mapper.GetTypes (ArgDirection.In, declMethod.GetParameters ()));
				ILGenerator ilg = method_builder.GetILGenerator ();

				//Mapper.GetTypes (ArgDirection.In, declMethod.GetParameters ())

				ParameterInfo[] delegateParms = declMethod.GetParameters ();
				Type[] hookupParms = new Type[delegateParms.Length+1];
				hookupParms[0] = typeof (BusObject);
				for (int i = 0; i < delegateParms.Length ; i++)
					hookupParms[i+1] = delegateParms[i].ParameterType;

				GenHookupMethod (ilg, declMethod, sendMethodCallMethod, Mapper.GetInterfaceName (iface), declMethod.Name, hookupParms);

				typeB.DefineMethodOverride (method_builder, declMethod);
			}
		}
开发者ID:guadalinex-archive,项目名称:guadalinex-v6,代码行数:22,代码来源:TypeImplementer.cs

示例14: Generate

        public override MethodBuilder Generate(TypeBuilder typeBuilder)
        {
            var targetMethodGenerator = new TargetedInvocationMethodGenerator(
                _methodMetadata,
                _targetField);

            var targetMethod = targetMethodGenerator.Generate(typeBuilder);

            var methodBuilder = GenerateMethod(
                typeBuilder,
                _methodMetadata,
                _dispatcherField,
                _methodInfoField,
                targetMethod);

            if (_methodMetadata.IsExplicitInterfaceImplementation)
            {
                typeBuilder.DefineMethodOverride(methodBuilder, _methodMetadata.Method);
            }

            return methodBuilder;
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:22,代码来源:TargetedMethodGenerator.cs

示例15: CreateMethod

        public static MethodBuilder CreateMethod(TypeBuilder typeBuilder, MethodInfo method)
        {
            var scope = method.IsPublic
                        ? MethodAttributes.Public
                        : MethodAttributes.Family;

            var parameters = method.GetParameters();

            var parameterTypes = parameters.Select(p => p.ParameterType)
                                           .ToArray();

            var methodBuilder = typeBuilder.DefineMethod(method.Name, scope | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.HideBySig, method.CallingConvention, method.ReturnType, parameterTypes);

            foreach (var parameter in parameters)
            {
                methodBuilder.DefineParameter(parameter.Position + 1, parameter.Attributes, parameter.Name);
            }

            typeBuilder.DefineMethodOverride(methodBuilder, method);

            return methodBuilder;
        }
开发者ID:scottjustin5000,项目名称:Adapters,代码行数:22,代码来源:AdapterEmitter.cs


注:本文中的System.Reflection.Emit.TypeBuilder.DefineMethodOverride方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。