本文整理汇总了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"));
}