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


C# Expression.CompileToMethod方法代码示例

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


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

示例1: CompileToMethod

partial         static void CompileToMethod(Expression<CompiledFactory> factoryExpression, ref CompiledFactory resultFactory)
        {
            resultFactory.ThrowIf(resultFactory != null);

            Interlocked.CompareExchange(ref _moduleBuilder, DefineDynamicModuleBuilder(), null);

            var typeName = "Factory" + Interlocked.Increment(ref TypeId);
            var typeBuilder = _moduleBuilder.DefineType(typeName, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract);

            var methodBuilder = typeBuilder.DefineMethod("GetService", MethodAttributes.Public | MethodAttributes.Static,
                typeof(object), new[] { typeof(object[]), typeof(Scope) });

            factoryExpression.CompileToMethod(methodBuilder);

            var dynamicType = typeBuilder.CreateType();
            resultFactory = (CompiledFactory)Delegate.CreateDelegate(typeof(CompiledFactory), dynamicType.GetMethod("GetService"));
        }
开发者ID:huangyingwen,项目名称:IocPerformance,代码行数:17,代码来源:FactoryCompiler.cs

示例2: DeclareProgram

 public Runtime.ExecuteHandler DeclareProgram(Expression<Runtime.ExecuteHandler> lambda)
 {
     var typeBuilder = _module.DefineType("Program", TypeAttributes.Class | TypeAttributes.Public);
     var methodBuilder =
         typeBuilder.DefineMethod
         (
             "Main",
             MethodAttributes.Public | MethodAttributes.Static,
             typeof(void),
             new[] { typeof(IDictionary<string, object>), typeof(Storage.IRepositoryFactory), typeof(CancellationToken) }
         );
     lambda.CompileToMethod(methodBuilder);
     var type = typeBuilder.CreateType();
     return (Runtime.ExecuteHandler)type.GetMethod("Main").CreateDelegate(typeof(Runtime.ExecuteHandler));
 }
开发者ID:jgabb8989,项目名称:DotQL,代码行数:15,代码来源:Emitter.cs

示例3: CompileToMethod

partial         static void CompileToMethod(Expression<FactoryDelegate> factoryExpression, Rules rules, ref FactoryDelegate result)
        {
            if (!rules.FactoryDelegateCompilationToDynamicAssembly)
                return;

            result.ThrowIf(result != null);

            var typeName = "Factory" + Interlocked.Increment(ref _typeId);
            var typeBuilder = GetDynamicAssemblyModuleBuilder().DefineType(typeName, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract);

            var methodBuilder = typeBuilder.DefineMethod(
                "GetService",
                MethodAttributes.Public | MethodAttributes.Static,
                typeof(object),
                new[] { typeof(AppendableArray), typeof(IResolverContextProvider), typeof(IScope) });

            factoryExpression.CompileToMethod(methodBuilder);

            var dynamicType = typeBuilder.CreateType();
            result = (FactoryDelegate)Delegate.CreateDelegate(typeof(FactoryDelegate), dynamicType.GetMethod("GetService"));
        }
开发者ID:RalfvandenBurg,项目名称:BoC,代码行数:21,代码来源:FactoryCompiler.cs


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