本文整理汇总了C#中Expression.Compile方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Compile方法的具体用法?C# Expression.Compile怎么用?C# Expression.Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.Compile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileCheck
public static void CompileCheck(FunctionContext context, Expression expression, int requiredStack)
{
var stack = expression.Compile(context);
if (stack != requiredStack)
throw new MondCompilerException(expression.FileName, expression.Line, "Bad stack state");
}
示例2: That
public static void That(Expression<Func<bool>> assertion, string msg = null)
{
var compiled = assertion.Compile();
bool? ok;
try {
ok = compiled();
} catch (Exception e) {
msg = MergeExceptionMessages(ExpressionToCode.AnnotatedToCode(assertion.Body), msg, e);
throw UnitTestingFailure.AssertionExceptionFactory(msg, e);
}
if (ok == false) {
msg = MergeExceptionMessages(ExpressionToCode.AnnotatedToCode(assertion.Body), msg);
throw UnitTestingFailure.AssertionExceptionFactory(msg, null);
}
}
示例3: F
public static int F(Expression<Func<int>> f)
{
return f.Compile()();
}
示例4: ExecuteIfNotInEditor
public static void ExecuteIfNotInEditor(Expression<Action> attempt, Action alternate = null)
{
try
{
if (!Application.isEditor)
{
attempt.Compile()();
}
else
{
Debug.Log("Execution requested of: " + attempt.Body);
if (alternate != null)
alternate();
}
}
catch (Exception e)
{
LogHandler.Handle(e);
}
}
示例5: Expression
/// <summary>
/// Used to create: {ValueLeft}{ComparisonOperator}{ValueRight}
/// Used to create: {UnaryOperation}{Value}
/// Used to create: {Value[0]}{BinaryOperator}{Value[1]}...{Value[n]}
/// </summary>
public Expression(Expression<Func<string>> operationExpression)
{
Func<string> deleg = operationExpression.Compile();
this.Value = deleg();
}
示例6: CompileBody
private Func<CodeContext, FunctionCode, object> CompileBody(Expression<Func<CodeContext/*!*/, FunctionCode/*!*/, object>> lambda) {
Func<CodeContext, FunctionCode, object> func;
PythonContext pc = (PythonContext)Ast.CompilerContext.SourceUnit.LanguageContext;
if (lambda.Body is ConstantExpression) {
// skip compiling for really simple code
object value = ((ConstantExpression)lambda.Body).Value;
return (codeCtx, functionCode) => value;
}
if (pc.ShouldInterpret((PythonCompilerOptions)Ast.CompilerContext.Options, Ast.CompilerContext.SourceUnit)) {
func = CompilerHelpers.LightCompile(lambda, false, pc.Options.CompilationThreshold);
} else {
func = lambda.Compile(Ast.CompilerContext.SourceUnit.EmitDebugSymbols);
}
return func;
}
示例7: DoNotLogMessageIfTraceDisabled
public void DoNotLogMessageIfTraceDisabled(Expression<Action<ILog>> expression, String expectedMessage)
{
var logger = new Logger("MyTestLogger", SourceLevels.Off);
var listener = new FakeTraceListener();
var testMethod = expression.Compile();
logger.TraceSource.Listeners.Add(listener);
testMethod(logger);
Assert.Equal(0, listener.Messages.Count(m => m == expectedMessage));
}
示例8: LogMessageIfTraceEnabled
public void LogMessageIfTraceEnabled(Expression<Action<ILog>> expression, String expectedMessage)
{
var logger = new Logger("MyTestLogger", SourceLevels.All);
var testMethod = expression.Compile();
lock (FakeTraceListener.Instance)
{
Trace.Listeners.Add(FakeTraceListener.Instance);
try
{
testMethod(logger);
Assert.Equal(1, FakeTraceListener.Instance.Messages.Count(m => m == "MyTestLogger: " + expectedMessage));
}
finally
{
Trace.Listeners.Remove(FakeTraceListener.Instance);
FakeTraceListener.Instance.Clear();
}
}
}