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


C# LambdaExpression类代码示例

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


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

示例1: UpdateLambda

 protected LambdaExpression UpdateLambda(LambdaExpression lambda, Type delegateType, Expression body, IEnumerable<ParameterExpression> parameters)
 {
     if (body != lambda.Body || parameters != lambda.Parameters || delegateType != lambda.Type)
     {
         return Expression.Lambda(delegateType, body, parameters);
     }
     return lambda;
 }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:8,代码来源:ExpressionVisitor.cs

示例2: VisitLambdaExpression

			public override void VisitLambdaExpression (LambdaExpression lambdaExpression)
			{
				var blockStatement = lambdaExpression.Body as BlockStatement;
				if (blockStatement != null)
					StatementIssueCollector.Collect (this, blockStatement);

				base.VisitLambdaExpression (lambdaExpression);
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:8,代码来源:UnreachableCodeIssue.cs

示例3: LightDelegateCreator

        internal LightDelegateCreator(Interpreter interpreter, LambdaExpression lambda)
        {
            Debug.Assert(interpreter != null);
            Debug.Assert(lambda != null);

            Interpreter = interpreter;
            _lambda = lambda;
        }
开发者ID:Corillian,项目名称:corefx,代码行数:8,代码来源:LightDelegateCreator.cs

示例4: Compile

		public static Delegate Compile (LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
		{
#if MONO_INTERPRETER
			return lambda.LightCompile ();
#else			
			throw new NotSupportedException ("System.Linq.Expression interpreter is missing");
#endif
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:LambdaCompiler.cs

示例5: LocalLookupVariable

		public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression)
		{
			Name = name;
			TypeRef = typeRef;
			StartPos = startPos;
			EndPos = endPos;
			IsConst = isConst;
			IsLoopVariable = isLoopVariable;
			Initializer = initializer;
			ParentLambdaExpression = parentLambdaExpression;
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:11,代码来源:LookupTableVisitor.cs

示例6: ExtendDeclaration

        public override void ExtendDeclaration(IDeclarationModel declaration, CompilationModel model)
        {
            // this only applies to methods
            var methodDecl = declaration as MethodDeclaration;
            if (methodDecl == null || methodDecl.Container == null)
                return;

            if (!methodDecl.Definition.Symbol.IsExtensionMethod)
                throw new CompilationException("The ScriptMixin attribute can only be applied to extension methods.", declaration);

            // remove the function from the container
            methodDecl.Container.RemoveMember(methodDecl);

            // get the extension target info
            var extTarget = methodDecl.Parameters[0];
            var extType = extTarget.Definition.Type;

            // rewrite first param as a local declaration to this context
            var thisDecl = new LocalDeclarationStatement { VariableDeclaration = new VariableDeclaration() };
            thisDecl.VariableDeclaration.Variables.Add(new VariableDeclarator
            {
                Definition = new LocalDefinition
                {
                    Name = extTarget.Name,
                    Type = extType
                },
                EqualsValueExpression = new LiteralExpression { Text = "this" }
            });

            // add the declaration to the method body
            methodDecl.Body.Statements.Insert(0, thisDecl);

            // create a lambda using the method body.
            var lambdaExpression = new LambdaExpression();
            lambdaExpression.Body = methodDecl.Body;

            for (int i = 1; i < methodDecl.Parameters.Count; i++)
                lambdaExpression.Parameters.Add(methodDecl.Parameters[i]);

            // create a global statement to set the prototype value
            var target = extType.GetFullName() + ".prototype." + methodDecl.Definition.Name;

            model.GlobalStatements.Add(new ExpressionStatement
            {
                Expression = new BinaryExpression
                {
                    LeftExpression = new LiteralExpression { Text = target },
                    RightExpression = lambdaExpression,
                    Operator = "="
                }
            });
        }
开发者ID:JimmyJune,项目名称:blade,代码行数:52,代码来源:ScriptMixinExtension.cs

示例7: VisitLambdaExpression

		public override void VisitLambdaExpression(LambdaExpression lambdaExpression)
		{
			foreach (var param in lambdaExpression.Parameters) {
				var result = context.Resolve(param);
				var local = result as LocalResolveResult;
				anonymousParameters.Add(local.Variable); 
			}
			base.VisitLambdaExpression(lambdaExpression);
			foreach (var param in lambdaExpression.Parameters) {
				var result = context.Resolve(param);
				var local = result as LocalResolveResult;
				anonymousParameters.Remove(local.Variable); 
			}
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:14,代码来源:VariableLookupVisitor.cs

示例8: GetLambdaReturnType

		public static IType GetLambdaReturnType(RefactoringContext context, LambdaExpression lambda)
		{
			LambdaResolveResult rr = context.Resolve(lambda) as LambdaResolveResult;
			if (rr == null)
				return SpecialType.UnknownType;
			if (rr.IsAsync) {
				// Unpack Task<T>
				if (rr.ReturnType.IsKnownType(KnownTypeCode.Task))
					return context.Compilation.FindType(KnownTypeCode.Void);
				else if (rr.ReturnType.IsKnownType(KnownTypeCode.TaskOfT) && rr.ReturnType.IsParameterized)
					return rr.ReturnType.TypeArguments[0];
			}
			return rr.ReturnType;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:14,代码来源:LambdaHelper.cs

示例9: AddVariable

		public void AddVariable(TypeReference typeRef, string name,
		                        Location startPos, Location endPos, bool isConst,
		                        bool isLoopVariable, Expression initializer,
		                        LambdaExpression parentLambdaExpression)
		{
			if (name == null || name.Length == 0) {
				return;
			}
			List<LocalLookupVariable> list;
			if (!variables.ContainsKey(name)) {
				variables[name] = list = new List<LocalLookupVariable>();
			} else {
				list = (List<LocalLookupVariable>)variables[name];
			}
			list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression));
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:16,代码来源:LookupTableVisitor.cs

示例10: VisitLambdaExpression

		public override void VisitLambdaExpression(LambdaExpression lambdaExpression) {
			AstNode oldMethod = _currentMethod;
			bool oldIsInsideLoop = _isInsideLoop;
			try {
				_currentMethod = lambdaExpression;
				_isInsideLoop = false;

				foreach (var p in lambdaExpression.Parameters)
					AddVariable(p, p.Name, p.ParameterModifier == ParameterModifier.Out || p.ParameterModifier == ParameterModifier.Ref);

				base.VisitLambdaExpression(lambdaExpression);
			}
			finally {
				_currentMethod = oldMethod;
				_isInsideLoop = oldIsInsideLoop;
			}
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:17,代码来源:VariableGatherer.cs

示例11: GetLambdaReturnType

		public static IType GetLambdaReturnType(RefactoringContext context, LambdaExpression lambda)
		{
			var parent = lambda.Parent;
			while (parent is ParenthesizedExpression)
				parent = parent.Parent;

			ITypeDefinition delegateTypeDef;
			if (parent is InvocationExpression) {
				var invocation = (InvocationExpression)parent;
				var argIndex = invocation.Arguments.TakeWhile (arg => !arg.Contains (lambda.StartLocation)).Count ();
				var resolveResult = (CSharpInvocationResolveResult)context.Resolve (invocation);
				delegateTypeDef = resolveResult.Arguments [argIndex].Type.GetDefinition ();
			} else {
				delegateTypeDef = context.Resolve (parent).Type.GetDefinition ();
			}
			if (delegateTypeDef == null)
				return null;
			var invokeMethod = delegateTypeDef.GetMethods (m => m.Name == "Invoke").FirstOrDefault ();
			if (invokeMethod == null)
				return null;
			return invokeMethod.ReturnType;
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:22,代码来源:LambdaHelper.cs

示例12: GetActions

		public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			Expression node = context.GetNode<IdentifierExpression>();
			if (node == null) {
				var mr = context.GetNode<MemberReferenceExpression>();
				if (mr == null || !mr.MemberNameToken.IsInside(context.Location))
					yield break;
				node = mr;
			}
			if (node == null)
				yield break;
			var rr = context.Resolve(node) as MethodGroupResolveResult;
			if (rr == null || rr.IsError)
				yield break;
			var type = TypeGuessing.GetValidTypes(context.Resolver, node).FirstOrDefault(t => t.Kind == TypeKind.Delegate);
			if (type == null)
				yield break;
			var invocationMethod = type.GetDelegateInvokeMethod();
			if (invocationMethod == null)
				yield break;

			yield return new CodeAction(
				context.TranslateString("Convert to lambda expression"), 
				script => {
					var invocation = new InvocationExpression(node.Clone(), invocationMethod.Parameters.Select(p => new IdentifierExpression(context.GetNameProposal(p.Name))));
					var lambda = new LambdaExpression {
						Body = invocation
					};
					lambda.Parameters.AddRange(
						invocation.Arguments
							.Cast<IdentifierExpression>()
							.Select(p => new ParameterDeclaration { Name = p.Identifier })
					);
					script.Replace(node, lambda);
				},
				node
			);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:38,代码来源:ConvertMethodGroupToLambdaAction.cs

示例13: PostWalk

 public virtual void PostWalk(LambdaExpression node) { }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:1,代码来源:PythonWalker.Generated.cs

示例14: Walk

 // LambdaExpression
 public virtual bool Walk(LambdaExpression node) { return true; }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:2,代码来源:PythonWalker.Generated.cs

示例15: MakeBinary

 public static BinaryExpression MakeBinary(ExpressionType binaryType, Expression left, Expression right, bool liftToNull, MethodInfo method, LambdaExpression conversion) {
     switch (binaryType) {
         case ExpressionType.Add:
             return Add(left, right, method);
         case ExpressionType.AddChecked:
             return AddChecked(left, right, method);
         case ExpressionType.Subtract:
             return Subtract(left, right, method);
         case ExpressionType.SubtractChecked:
             return SubtractChecked(left, right, method);
         case ExpressionType.Multiply:
             return Multiply(left, right, method);
         case ExpressionType.MultiplyChecked:
             return MultiplyChecked(left, right, method);
         case ExpressionType.Divide:
             return Divide(left, right, method);
         case ExpressionType.Modulo:
             return Modulo(left, right, method);
         case ExpressionType.Power:
             return Power(left, right, method);
         case ExpressionType.And:
             return And(left, right, method);
         case ExpressionType.AndAlso:
             return AndAlso(left, right, method);
         case ExpressionType.Or:
             return Or(left, right, method);
         case ExpressionType.OrElse:
             return OrElse(left, right, method);
         case ExpressionType.LessThan:
             return LessThan(left, right, liftToNull, method);
         case ExpressionType.LessThanOrEqual:
             return LessThanOrEqual(left, right, liftToNull, method);
         case ExpressionType.GreaterThan:
             return GreaterThan(left, right, liftToNull, method);
         case ExpressionType.GreaterThanOrEqual:
             return GreaterThanOrEqual(left, right, liftToNull, method);
         case ExpressionType.Equal:
             return Equal(left, right, liftToNull, method);
         case ExpressionType.NotEqual:
             return NotEqual(left, right, liftToNull, method);
         case ExpressionType.ExclusiveOr:
             return ExclusiveOr(left, right, method);
         case ExpressionType.Coalesce:
             return Coalesce(left, right, conversion);
         case ExpressionType.ArrayIndex:
             return ArrayIndex(left, right);
         case ExpressionType.RightShift:
             return RightShift(left, right, method);
         case ExpressionType.LeftShift:
             return LeftShift(left, right, method);
         case ExpressionType.Assign:
             return Assign(left, right);
         case ExpressionType.AddAssign:
             return AddAssign(left, right, method, conversion);
         case ExpressionType.AndAssign:
             return AndAssign(left, right, method, conversion);
         case ExpressionType.DivideAssign:
             return DivideAssign(left, right, method, conversion);
         case ExpressionType.ExclusiveOrAssign:
             return ExclusiveOrAssign(left, right, method, conversion);
         case ExpressionType.LeftShiftAssign:
             return LeftShiftAssign(left, right, method, conversion);
         case ExpressionType.ModuloAssign:
             return ModuloAssign(left, right, method, conversion);
         case ExpressionType.MultiplyAssign:
             return MultiplyAssign(left, right, method, conversion);
         case ExpressionType.OrAssign:
             return OrAssign(left, right, method, conversion);
         case ExpressionType.PowerAssign:
             return PowerAssign(left, right, method, conversion);
         case ExpressionType.RightShiftAssign:
             return RightShiftAssign(left, right, method, conversion);
         case ExpressionType.SubtractAssign:
             return SubtractAssign(left, right, method, conversion);
         case ExpressionType.AddAssignChecked:
             return AddAssignChecked(left, right, method, conversion);
         case ExpressionType.SubtractAssignChecked:
             return SubtractAssignChecked(left, right, method, conversion);
         case ExpressionType.MultiplyAssignChecked:
             return MultiplyAssignChecked(left, right, method, conversion);
         default:
             throw Error.UnhandledBinary(binaryType);
     }
 }
开发者ID:whereisaaron,项目名称:mono,代码行数:84,代码来源:BinaryExpression.cs


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