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


C# Linq.Expressions类代码示例

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


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

示例1: TransformSet

        internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, Operators op) {
            MSAst.Expression variable = _reference.Variable;
            MSAst.Expression assignment;

            Type vt = variable != null ? variable.Type : typeof(object);

            if (op != Operators.None) {
                right = Binders.Operation(
                    ag.BinderState,
                    vt,
                    StandardOperators.FromOperator(op),
                    Transform(ag, vt),
                    right
                );
            }

            if (variable != null) {
                assignment = AstUtils.Assign(variable, AstGenerator.ConvertIfNeeded(right, variable.Type));
            } else {
                assignment = AstUtils.Assign(_name, right);
            }

            SourceSpan aspan = span.IsValid ? new SourceSpan(Span.Start, span.End) : SourceSpan.None;
            return ag.AddDebugInfoAndVoid(assignment, aspan);
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:25,代码来源:NameExpression.cs

示例2: TransformWriteVariable

 internal override MSA.Expression/*!*/ TransformWriteVariable(AstGenerator/*!*/ gen, MSA.Expression/*!*/ rightValue) {
     if (gen.CompilerOptions.IsEval || gen.GetCurrentNonSingletonModule() != null) {
         return Methods.SetClassVariable.OpCall(AstFactory.Box(rightValue), gen.CurrentScopeVariable, AstUtils.Constant(Name));
     } else {
         return Methods.SetObjectClassVariable.OpCall(AstFactory.Box(rightValue), gen.CurrentScopeVariable, AstUtils.Constant(Name));
     }
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:ClassVariable.cs

示例3: AplusScope

        public AplusScope(AplusScope parent,
            string name,
            Aplus runtime = null,
            DLR.ParameterExpression runtimeParam = null,
            DLR.ParameterExpression moduleParam = null,
            DLR.LabelTarget returnTarget = null,
            bool isEval = false,
            bool isMethod = false,
            bool isAssignment = false)
        {
            this.parent = parent;
            this.name = name;
            this.runtime = runtime;
            this.runtimeParam = runtimeParam;
            this.moduleParam = moduleParam;

            this.returnTarget = returnTarget;

            this.variables = new Dictionary<string, DLR.ParameterExpression>();

            this.callbackInfo = new CallbackInfoStorage();

            this.iseval = isEval;

            this.ismethod = isMethod;
            this.isAssignment = isAssignment;

            InheritProperties(parent);
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:29,代码来源:AplusScope.cs

示例4: CreateLambda

        private MSA.Expression/*!*/ TransformBody(AstGenerator/*!*/ gen, MSA.Expression/*!*/ methodDefinitionVariable) {
            string encodedName = RubyExceptionData.EncodeMethodName(gen.SourceUnit, _name, Location);
            
            ScopeBuilder scope = new ScopeBuilder();
            MSA.Expression parentScope = gen.CurrentScopeVariable;

            MSA.ParameterExpression[] parameters = DefineParameters(gen, scope);
            MSA.Expression currentMethodVariable = scope.DefineHiddenVariable("#method", typeof(RubyMethodInfo));
            MSA.Expression rfcVariable = scope.DefineHiddenVariable("#rfc", typeof(RuntimeFlowControl));
            MSA.Expression scopeVariable = scope.DefineHiddenVariable("#scope", typeof(RubyMethodScope));
            MSA.Expression selfParameter = parameters[0];
            MSA.Expression blockParameter = parameters[1];

            gen.EnterMethodDefinition(
                scope,
                selfParameter,
                scopeVariable,
                blockParameter,
                rfcVariable,
                currentMethodVariable,
                _name,
                _parameters
            );

            DefinedScope.TransformLocals(scope);

            MSA.ParameterExpression unwinder = scope.DefineHiddenVariable("#unwinder", typeof(MethodUnwinder));

            MSA.Expression body = AstFactory.MakeUserMethodBody(
                gen, Location.End.Line,
                blockParameter,
                rfcVariable,
                unwinder,
                Ast.Block(
                    Ast.Assign(currentMethodVariable, methodDefinitionVariable),

                    Ast.Assign(scopeVariable, Methods.CreateMethodScope.OpCall(
                        scope.VisibleVariables(), parentScope, currentMethodVariable, rfcVariable, selfParameter, blockParameter)
                    ),
                
                    _parameters.TransformOptionalsInitialization(gen),
                    gen.TraceEnabled ? Methods.TraceMethodCall.OpCall(scopeVariable, Ast.Convert(AstUtils.Constant(gen.SourceUnit.Path), typeof(string)), AstUtils.Constant(Location.Start.Line)) : AstUtils.Empty(),
                    Body.TransformResult(gen, ResultOperation.Return),
                    AstUtils.Empty()
                ),
                ResultOperation.Return,
                (gen.Profiler != null) ? gen.Profiler.GetTickIndex(encodedName) : -1,
                (gen.Profiler != null) ? scope.DefineHiddenVariable("#stamp", typeof(long)) : null,
                gen.ReturnLabel
            );

            body = gen.AddReturnTarget(scope.CreateScope(body));
            gen.LeaveMethodDefinition();

            return CreateLambda(
                encodedName, 
                parameters, 
                body
            );
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:60,代码来源:MethodDeclaration.cs

示例5: TransformWriteVariable

        /*!*/
        internal override MSA.Expression TransformWriteVariable(AstGenerator/*!*/ gen, MSA.Expression/*!*/ rightValue)
        {
            Assert.NotNull(gen, rightValue);

            // no-op
            return rightValue;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:8,代码来源:Placeholder.cs

示例6: IsTrue

 public static MSA.Expression/*!*/ IsTrue(MSA.Expression/*!*/ expression) {
     if (expression.Type == typeof(bool)) {
         return expression;
     } else {
         return Methods.IsTrue.OpCall(Box(expression));
     }
 }
开发者ID:techarch,项目名称:ironruby,代码行数:7,代码来源:AstFactory.cs

示例7: InvokeTarget

        private object InvokeTarget(MSAst.LambdaExpression code, Scope scope) {
            if (scope == _optimizedContext.Scope) {
                EnsureCompiled();

                if (_context.SourceUnit.Kind == SourceCodeKind.Expression) {
                    return OptimizedEvalWrapper();
                }
                return _optimizedTarget();
            }

            // if we're running different code then re-compile the code under a new scope
            if (_unoptimizedCode == null) {
                // TODO: Copy instead of mutate
                ((PythonCompilerOptions)_context.Options).Optimized = false;
                Interlocked.CompareExchange(
                    ref _unoptimizedCode,
                    _ast.TransformToAst(CompilationMode.Lookup, _context),
                    null
                );
            }

            if (_context.SourceUnit.Kind == SourceCodeKind.Expression) {
                return EvalWrapper(scope);
            }
            return _unoptimizedCode.Run(scope);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:26,代码来源:RuntimeScriptCode.cs

示例8: PythonScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {            
            MSAst.Expression finalBody = Ast.Block(
                new[] { _globalCtx },
                Ast.Assign(
                    _globalCtx,
                    Ast.Call(typeof(PythonOps).GetMethod("CreateTopLevelCodeContext"),
                        _globalScope,
                        _language
                    )
                ),
                body
            );

            PythonCompilerOptions pco = ((PythonCompilerOptions)context.Options);
            string name = pco.ModuleName ?? "<unnamed>";
            var lambda = Ast.Lambda<Func<Scope, LanguageContext, object>>(
                finalBody, 
                name,
                new[] { _globalScope, _language } 
            );


            Func<Scope, LanguageContext, object> func;
            // TODO: adaptive compilation should be eanbled
            /*PythonContext pc = (PythonContext)context.SourceUnit.LanguageContext;
            if (pc.ShouldInterpret(pco, context.SourceUnit)) {
                func = CompilerHelpers.LightCompile(lambda);
            } else*/ {
                func = lambda.Compile(context.SourceUnit.EmitDebugSymbols);
            }

            return new PythonScriptCode(func, context.SourceUnit);
        }
开发者ID:toddb,项目名称:ironruby,代码行数:33,代码来源:DictionaryGlobalAllocator.cs

示例9: IsFalse

 public static MSA.Expression/*!*/ IsFalse(MSA.Expression/*!*/ expression) {
     if (expression.Type == typeof(bool)) {
         return Ast.Not(expression);
     } else {
         return Methods.IsFalse.OpCall(AstUtils.Box(expression));
     }
 }
开发者ID:atczyc,项目名称:ironruby,代码行数:7,代码来源:AstFactory.cs

示例10: PythonScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {
            PythonCompilerOptions pco = ((PythonCompilerOptions)context.Options);
            PythonContext pc = (PythonContext)context.SourceUnit.LanguageContext;

            if (body is MSAst.ConstantExpression) {
                object value = ((MSAst.ConstantExpression)body).Value;
                return new PythonScriptCode(codeCtx => value, context.SourceUnit);
            }

            var lambda = Ast.Lambda<Func<CodeContext, object>>(
                Utils.Convert(body, typeof(object)),
                pco.ModuleName ?? "<unnamed>",
                ArrayGlobalAllocator._globalContextList
            );

            Func<CodeContext, object> func;

            if (pc.ShouldInterpret(pco, context.SourceUnit)) {
                func = CompilerHelpers.LightCompile(lambda);
            } else {
                func = lambda.Compile(context.SourceUnit.EmitDebugSymbols);
            }

            return new PythonScriptCode(func, context.SourceUnit);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:25,代码来源:DictionaryGlobalAllocator.cs

示例11: RubyMethodBody

        internal RubyMethodBody(MethodDeclaration/*!*/ ast, MSA.SymbolDocumentInfo document, RubyEncoding/*!*/ encoding) {
            Assert.NotNull(ast, encoding);

            _ast = ast;
            _document = document;
            _encoding = encoding;
        }
开发者ID:BrianGenisio,项目名称:ironruby,代码行数:7,代码来源:RubyMethodBody.cs

示例12: TransformSet

 internal override MSAst.Expression TransformSet(SourceSpan span, MSAst.Expression right, PythonOperationKind op) {
     if (op == PythonOperationKind.None) {
         return GlobalParent.AddDebugInfoAndVoid(
             GlobalParent.Set(
                 typeof(object),
                 _name,
                 _target,
                 right
             ),
             span
         );
     } else {
         MSAst.ParameterExpression temp = Ast.Variable(typeof(object), "inplace");
         return GlobalParent.AddDebugInfo(
             Ast.Block(
                 new[] { temp },
                 Ast.Assign(temp, _target),
                 SetMemberOperator(right, op, temp),
                 AstUtils.Empty()
             ),
             Span.Start,
             span.End
         );
     }
 }
开发者ID:mstram,项目名称:ironruby,代码行数:25,代码来源:MemberExpression.cs

示例13: SetVariable

        /// <summary>
        /// Constructs a DLR Expression tree representing setting a variable inside a context.
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="variableContainer">The container where the lookup should be performed</param>
        /// <param name="contextParts">
        /// Contains 2 strings:
        ///  1. The name of the context
        ///  2. The name of the variable inside the context
        /// </param>
        /// <param name="value">Expression containing the value of the variable</param>
        /// <remarks>
        /// The returned DLR Expression tree will try to fetch the context inside the container.
        /// If the context does not exists, this will result an exception.
        /// If the exception occured, the context will be created inside the catch block.
        /// After this the context surely exists, so we can simply set the variable to the provided value.
        /// 
        /// </remarks>
        /// <returns>>Expression tree for setting a value for the given context parts</returns>
        internal static DLR.Expression SetVariable(Aplus runtime, DLR.Expression variableContainer, string[] contextParts, DLR.Expression value)
        {
            // Get the context
            DLR.Expression getContext =
                DLR.Expression.TryCatch(
                    DLR.Expression.Dynamic(
                        runtime.GetMemberBinder(contextParts[0]),
                        typeof(object),
                        variableContainer
                    ),
                    DLR.Expression.Catch(
                // Context not found, create one!
                        typeof(Error.Value),
                        DLR.Expression.Dynamic(
                            runtime.SetMemberBinder(contextParts[0]),
                            typeof(object),
                            variableContainer,
                            DLR.Expression.Constant(new ScopeStorage())
                        )
                    )
                );

            DLR.Expression setVariable = DLR.Expression.Dynamic(
                runtime.SetMemberBinder(contextParts[1]),
                typeof(object),
                getContext,
                value
            );
            return setVariable;
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:49,代码来源:VariableHelper.cs

示例14: RuntimeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ lambda, CompilerContext/*!*/ compilerContext, PythonAst/*!*/ ast) {
            PythonContext context = (PythonContext)compilerContext.SourceUnit.LanguageContext;

            Type t = _typeGen.FinishType();
#if SILVERLIGHT
            _finalType.Value = t;
#endif

            // create the CodeContext for this optimized module
            InitOptimizedCodeContext(t);
            t.GetField("__global_context").SetValue(null, _context);

            // publish the cached constants
            foreach (var ci in _constants) {
                FieldInfo fi = t.GetField(ci.Value.Field.Name);
                fi.SetValue(null, ci.Key);
            }

            // publish all of the call site instances
            foreach (SiteInfo si in _sites) {
                FieldInfo fi = t.GetField(si.Field.Name);

                fi.SetValue(null, CallSite.Create(si.DelegateType, si.Binder));
            }

            // initialize all of the cached symbol IDs.
            ScriptingRuntimeHelpers.InitializeSymbols(t);

            string name = ((PythonCompilerOptions)compilerContext.Options).ModuleName ?? "<unnamed>";
            var func = Ast.Lambda<Func<object>>(lambda, name, new MSAst.ParameterExpression[0]);
            return new RuntimeScriptCode(compilerContext, func, ast, _context);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:32,代码来源:StaticGlobalAllocator.cs

示例15: RuntimeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast, Dictionary<int, bool> handlerLocations, Dictionary<int, Dictionary<int, bool>> loopAndFinallyLocations) {
            // create the CodeContext
            PythonGlobal[] globalArray = new PythonGlobal[_globals.Count];

            // now fill in the dictionary and create the array
            foreach (var global in _globals) {
                globalArray[global.Value.Index] = _globalVals[global.Key];
            }
            
            _array.Array = globalArray;

            // finally build the funcion that's closed over the array and
            string name = ((PythonCompilerOptions)context.Options).ModuleName ?? "<unnamed>";
            var func = Ast.Lambda<Func<FunctionCode, object>>(
                Ast.Block(
                    new[] { _globalArray, _globalContext },
                    Ast.Assign(_globalArray, Ast.Constant(globalArray)),
                    Ast.Assign(_globalContext, Ast.Constant(_context)),
                    Utils.Convert(body, typeof(object))
                ),
                name,
                new [] { AstGenerator._functionCode }
            );

            return new RuntimeScriptCode(context, func, ast, _context);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:26,代码来源:ArrayGlobalAllocator.cs


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