• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Linq.Expressions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: DefineParameters

        private MSA.ParameterExpression[]/*!*/ DefineParameters(out MSA.Expression/*!*/ selfVariable, out MSA.Expression/*!*/ blockParamVariable) {
            var parameters = new MSA.ParameterExpression[
                HiddenParameterCount +
                (HasFormalParametersInArray ? 1 : _parameters.LeftValues.Count) + 
                (HasUnsplatParameter ? 1 : 0)
            ];

            // hidden parameters:
            // #proc must be the first one - it is used as instance target for method invocation:
            blockParamVariable = parameters[0] = Ast.Parameter(typeof(BlockParam), "#proc");
            selfVariable = parameters[1] = Ast.Parameter(typeof(object), "#self");

            int i = HiddenParameterCount;
            if (HasFormalParametersInArray) {
                parameters[i++] = Ast.Parameter(typeof(object[]), "#parameters");
            } else {
                for (; i < parameters.Length; i++) {
                    parameters[i] = Ast.Parameter(typeof(object), "#" + (i - HiddenParameterCount));
                }
            }

            if (HasUnsplatParameter) {
                parameters[i] = Ast.Parameter(typeof(RubyArray), "#array");
            }

            return parameters;
        }
开发者ID:techarch,项目名称:ironruby,代码行数:27,代码来源:BlockDefinition.cs


示例17: RuntimeScriptCode

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

            // now fill in the dictionary and create the array
            foreach (var global in _globals) {
                SymbolId globalName = SymbolTable.StringToId(global.Key);
                
                globalArray[global.Value.Index] = _globalVals[globalName];
            }
            
            _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<object>>(
                Ast.Block(
                    new[] { _globalArray, _globalContext },
                    Ast.Assign(_globalArray, Ast.Constant(globalArray)),
                    Ast.Assign(_globalContext, Ast.Constant(_context)),
                    body
                ),
                name,
                new MSAst.ParameterExpression[0]
            );

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


示例18: CloneMemoryMappedFile

        /// <summary>
        /// If the argument is Memory-mapped file and the mode is read only, we clone it.
        /// The clone creates an ordinary array.
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        public static DLR.Expression CloneMemoryMappedFile(DLR.Expression argument)
        {
            DLR.ParameterExpression argumentParam = DLR.Expression.Parameter(typeof(AType), "__VALUE__");

            return DLR.Expression.Block(
                new DLR.ParameterExpression[] { argumentParam },
                DLR.Expression.Assign(argumentParam, argument),
                DLR.Expression.IfThen(
                    DLR.Expression.AndAlso(
                            DLR.Expression.Property(argumentParam, "IsMemoryMappedFile"),
                            DLR.Expression.Equal(
                                DLR.Expression.Property(
                                    DLR.Expression.Convert(
                                        DLR.Expression.Property(argumentParam, "Data"),
                                        typeof(IMapped)
                                    ),
                                    "Mode"
                                ),
                                DLR.Expression.Constant(MemoryMappedFileMode.Read)
                            )
                        ),
                        DLR.Expression.Assign(
                            DLR.Expression.Property(argumentParam, "Data"),
                            DLR.Expression.Property(
                                DLR.Expression.Call(
                                    argumentParam,
                                    typeof(AType).GetMethod("Clone")
                                ),
                                "Data"
                            )
                        )
                    ),
                    argumentParam
            );
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:41,代码来源:Tools.cs


示例19: Logical

 public static MSA.Expression/*!*/ Logical(MSA.Expression/*!*/ left, MSA.Expression/*!*/ right, bool isConjunction) {
     if (isConjunction) {
         return Ast.AndAlso(left, right);
     } else {
         return Ast.OrElse(left, right);
     }
 }
开发者ID:atczyc,项目名称:ironruby,代码行数:7,代码来源:AstFactory.cs


示例20: SavableScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {
            MSAst.ParameterExpression scope = Ast.Parameter(typeof(Scope), "$scope");
            MSAst.ParameterExpression language = Ast.Parameter(typeof(LanguageContext), "$language ");

            // finally build the funcion that's closed over the array and
            var func = Ast.Lambda<Func<Scope, LanguageContext, object>>(
                Ast.Block(
                    new[] { GlobalArray },
                    Ast.Assign(
                        GlobalArray, 
                        Ast.Call(
                            null,
                            typeof(PythonOps).GetMethod("GetGlobalArray"),
                            scope
                        )
                    ),
                    Utils.Convert(body, typeof(object))
                ),
                ((PythonCompilerOptions)context.Options).ModuleName,
                new MSAst.ParameterExpression[] { scope, language }
            );

            PythonCompilerOptions pco = context.Options as PythonCompilerOptions;

            return new SavableScriptCode(func, context.SourceUnit, GetNames(), pco.ModuleName);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:26,代码来源:SavableGlobalAllocator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Media.SoundPlayer类代码示例发布时间:2022-05-24
下一篇:
C# System.Linq类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap