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


C# Expression类代码示例

本文整理汇总了C#中Expression的典型用法代码示例。如果您正苦于以下问题:C# Expression类的具体用法?C# Expression怎么用?C# Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ConversionToLessSpecficWithBoxingToObject

		public void ConversionToLessSpecficWithBoxingToObject()
		{
			Expression<object> expr = new Expression<object>("2 + 2");
			object result = expr.Evaluate();

			Assert.AreEqual(4, result);
		}
开发者ID:chenzuo,项目名称:nquery,代码行数:7,代码来源:ExpressionTests.cs

示例2: MethodCall

        public MethodCall(Expression target, string/*!*/ methodName, Arguments args, Block block, SourceSpan location)
            : base(args, block, location) {
            Assert.NotEmpty(methodName);

            _methodName = methodName;
            _target = target;
        }
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:MethodCall.cs

示例3: Coalesce

 public static Expression Coalesce(LambdaBuilder builder, Expression left, Expression right)
 {
     ParameterExpression temp;
     Expression result = Coalesce(left, right, out temp);
     builder.AddHiddenVariable(temp);
     return result;
 }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:BinaryExpression.cs

示例4: UnaryExpression

 public UnaryExpression(Terminal op, Expression expression)
 {
     Operator = op;
     Expression = expression;
     AddAttribute(new OperatorAttr(op));
     AddChild(expression);
 }
开发者ID:nmenshov,项目名称:Iron-C--,代码行数:7,代码来源:UnaryExpression.cs

示例5: Collect

 public void Collect(Expression tvBasePointer, int basePointerSize, Expression eField, Expression effectiveAddress)
 {
     this.basePointer = tvBasePointer;
     this.basePointerSize = basePointerSize;
     this.eField = eField;
     effectiveAddress.Accept(this);
 }
开发者ID:nemerle,项目名称:reko,代码行数:7,代码来源:AddressTraitCollector.cs

示例6: ComInvokeBinder

        internal ComInvokeBinder(
                CallInfo callInfo, 
                DynamicMetaObject[] args,
                bool[] isByRef,
                BindingRestrictions restrictions, 
                Expression method, 
                Expression dispatch, 
                ComMethodDesc methodDesc
                )
        {
            Debug.Assert(callInfo != null, "arguments");
            Debug.Assert(args != null, "args");
            Debug.Assert(isByRef != null, "isByRef");
            Debug.Assert(method != null, "method");
            Debug.Assert(dispatch != null, "dispatch");

            Debug.Assert(TypeUtils.AreReferenceAssignable(typeof(ComMethodDesc), method.Type), "method");
            Debug.Assert(TypeUtils.AreReferenceAssignable(typeof(IDispatch), dispatch.Type), "dispatch");

            _method = method;
            _dispatch = dispatch;
            _methodDesc = methodDesc;

            _callInfo = callInfo;
            _args = args;
            _isByRef = isByRef;
            _restrictions = restrictions;

            // Set Instance to some value so that CallBinderHelper has the right number of parameters to work with
            _instance = dispatch;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:31,代码来源:ComInvokeBinder.cs

示例7: EmitExpressionAsVoid

        /// <summary>
        /// Emits an expression and discards the result.  For some nodes this emits
        /// more optimial code then EmitExpression/Pop
        /// </summary>
        private void EmitExpressionAsVoid(Expression node) {
            Debug.Assert(node != null);

            ExpressionStart startEmitted = EmitExpressionStart(node);

            switch (node.NodeType) {
                case ExpressionType.Assign:
                    EmitAssign((BinaryExpression)node, EmitAs.Void);
                    break;
                case ExpressionType.Block:
                    Emit((BlockExpression)node, EmitAs.Void);
                    break;
                case ExpressionType.Throw:
                    EmitThrow((UnaryExpression)node, EmitAs.Void);
                    break;
                case ExpressionType.Constant:
                case ExpressionType.Default:
                case ExpressionType.Parameter:
                    // no-op
                    break;
                default:
                    EmitExpression(node, false);
                    if (node.Type != typeof(void)) {
                        _ilg.Emit(OpCodes.Pop);
                    }
                    break;
            }
            EmitExpressionEnd(startEmitted);
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:33,代码来源:LambdaCompiler.Expressions.cs

示例8: SetParent

        public override void SetParent(Expression parent)
        {
            base.SetParent(parent);

            if (Value != null)
                Value.SetParent(this);
        }
开发者ID:krixalis,项目名称:Mond,代码行数:7,代码来源:ReturnExpression.cs

示例9: Equals

        public override bool Equals(Expression E)
        {
            Product P = E as Product;
            if (ReferenceEquals(P, null)) return base.Equals(E);

            return Terms.SequenceEqual(P.Terms);
        }
开发者ID:JackWangCUMT,项目名称:ComputerAlgebra,代码行数:7,代码来源:Product.cs

示例10: SimpleCallHelper

        /// <summary>
        /// The helper to create the AST method call node. Will add conversions (Utils.Convert)
        /// to parameters and instance if necessary.
        /// </summary>
        public static MethodCallExpression SimpleCallHelper(Expression instance, MethodInfo method, params Expression[] arguments) {
            ContractUtils.RequiresNotNull(method, "method");
            ContractUtils.Requires(instance != null ^ method.IsStatic, "instance");
            ContractUtils.RequiresNotNullItems(arguments, "arguments");

            ParameterInfo[] parameters = method.GetParameters();

            ContractUtils.Requires(arguments.Length == parameters.Length, "arguments", "Incorrect number of arguments");

            if (instance != null) {
                instance = Convert(instance, method.DeclaringType);
            }

            Expression[] convertedArguments = ArgumentConvertHelper(arguments, parameters);

            ReadOnlyCollection<Expression> finalArgs;
            if (convertedArguments == arguments) {
                // we didn't convert anything, just convert the users original
                // array to a readonly collection.
                finalArgs = convertedArguments.ToReadOnly();
            } else {
                // we already copied the array so just stick it in a readonly collection.
                finalArgs = new ReadOnlyCollection<Expression>(convertedArguments);
            }

            // the arguments are now all correct, avoid re-validating the call parameters and
            // directly create the expression.
            return Expression.Call(instance, method, finalArgs);
        }
开发者ID:techarch,项目名称:ironruby,代码行数:33,代码来源:MethodCallExpression.cs

示例11: ArgumentConvertHelper

        private static Expression[] ArgumentConvertHelper(Expression[] arguments, ParameterInfo[] parameters) {
            Debug.Assert(arguments != null);
            Debug.Assert(arguments != null);

            Expression[] clone = null;
            for (int arg = 0; arg < arguments.Length; arg++) {
                Expression argument = arguments[arg];
                if (!CompatibleParameterTypes(parameters[arg].ParameterType, argument.Type)) {
                    // Clone the arguments array if needed
                    if (clone == null) {
                        clone = new Expression[arguments.Length];
                        // Copy the expressions into the clone
                        for (int i = 0; i < arg; i++) {
                            clone[i] = arguments[i];
                        }
                    }

                    argument = ArgumentConvertHelper(argument, parameters[arg].ParameterType);
                }

                if (clone != null) {
                    clone[arg] = argument;
                }
            }
            return clone ?? arguments;
        }
开发者ID:techarch,项目名称:ironruby,代码行数:26,代码来源:MethodCallExpression.cs

示例12: ShouldSolveSystemWith1EquationAnd2Variables

        public void ShouldSolveSystemWith1EquationAnd2Variables()
        {
            //x+y=10    x=6; y=4
            //x-y=2
            var variableX = new Variable("x");
            var variableY = new Variable("y");

            var left1FirstEq = new Expression(1, variableX);
            var left2FirstEq = new Expression(1, variableY);
            var rightFirstEq = new Expression(10, Variable.NULL);

            var left1SecondEq = new Expression(1, variableX);
            var left2SecondEq = new Expression(-1, variableY);
            var rightSecondEq = new Expression(2, Variable.NULL);

            var firstEquation = new Equation(new List<Expression>() { left1FirstEq, left2FirstEq }, rightFirstEq);
            var secondEquation = new Equation(new List<Expression>() {left1SecondEq, left2SecondEq}, rightSecondEq);

            var target = new SystemOfEquations(new List<Equation>() {firstEquation, secondEquation});
            target.Solve();
            var resultX = variableX.Value;
            var resultY = variableY.Value;

            Assert.AreEqual(1, resultX.Count);
            Assert.AreEqual(1, resultY.Count);
            Assert.AreEqual(Variable.NULL, resultX.First().Variable);
            Assert.AreEqual(6, resultX.First().Coefficient);
            Assert.AreEqual(Variable.NULL, resultY.First().Variable);
            Assert.AreEqual(4, resultY.First().Coefficient);
        }
开发者ID:qqudesnik,项目名称:Gauss,代码行数:30,代码来源:SystemOfEquationsTests.cs

示例13: Binary

 public Binary(SourceSpan span, Operator op, Expression left, Expression right)
     : base(span)
 {
     _op = op;
     _left = left;
     _right = right;
 }
开发者ID:whoisjake,项目名称:Infix,代码行数:7,代码来源:Binary.cs

示例14: ForLoopStatement

		public ForLoopStatement(ScriptLoadingContext lcontext, Token nameToken, Token forToken)
			: base(lcontext)
		{
			//	for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end | 

			// lexer already at the '=' ! [due to dispatching vs for-each]
			CheckTokenType(lcontext, TokenType.Op_Assignment);

			m_Start = Expression.Expr(lcontext);
			CheckTokenType(lcontext, TokenType.Comma);
			m_End = Expression.Expr(lcontext);

			if (lcontext.Lexer.Current.Type == TokenType.Comma)
			{
				lcontext.Lexer.Next();
				m_Step = Expression.Expr(lcontext);
			}
			else
			{
				m_Step = new LiteralExpression(lcontext, DynValue.NewNumber(1));
			}

			lcontext.Scope.PushBlock();
			m_VarName = lcontext.Scope.DefineLocal(nameToken.Text);
			m_RefFor = forToken.GetSourceRef(CheckTokenType(lcontext, TokenType.Do));
			m_InnerBlock = new CompositeStatement(lcontext);
			m_RefEnd = CheckTokenType(lcontext, TokenType.End).GetSourceRef();
			m_StackFrame = lcontext.Scope.PopBlock();

			lcontext.Source.Refs.Add(m_RefFor);
			lcontext.Source.Refs.Add(m_RefEnd);
		}		
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:32,代码来源:ForLoopStatement.cs

示例15: BinaryOperationExpressionCombinesSequences

        public void BinaryOperationExpressionCombinesSequences()
        {
            var a = new Expression[] { 1, 2, null, "Hello", JS.Function().Call() };
            var c = a.Combined(BinaryOperator.Add);

            Assert.AreEqual("1+2+null+\"Hello\"+(function(){})();", c.ToString());
        }
开发者ID:DaveVdE,项目名称:adamjsgenerator,代码行数:7,代码来源:BinaryOperationExpressionTests.cs


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