本文整理匯總了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"));
}
示例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));
}
示例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"));
}