當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。