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


C# LambdaExpression.AddParameter方法代码示例

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


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

示例1: GetLambdaExpression

        /// <summary>
        /// Reads a lambda expression.
        /// </summary>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the expression.</returns>
        private LambdaExpression GetLambdaExpression(bool unsafeCode)
        {
            Param.Ignore(unsafeCode);

            // Create an empty lambda expression.
            LambdaExpression lambdaExpression = new LambdaExpression();

            // Check whether the next symbol is an opening parenthesis.
            Symbol symbol = this.GetNextSymbol();

            Node<CsToken> previousTokenNode = this.tokens.Last;
            ICollection<Parameter> parameters = null;

            if (symbol.SymbolType == SymbolType.OpenParenthesis)
            {
                parameters = this.ParseAnonymousMethodParameterList(unsafeCode);
            }
            else
            {
                // Since the statement did not begin with an opening parenthesis,
                // it must begin with a single unknown symbol.
                if (symbol.SymbolType != SymbolType.Other)
                {
                    throw new SyntaxException(this.document.SourceCode, symbol.LineNumber);
                }

                CsToken token = this.GetToken(CsTokenType.Other, SymbolType.Other);
                this.tokens.Add(token);

                // Add the single parameter.
                lambdaExpression.AddParameter(new Parameter(
                    null, 
                    token.Text, 
                    ParameterModifiers.None, 
                    token.Location,
                    new CsTokenList(this.tokens, this.tokens.Last, this.tokens.Last)));
            }

            // Get the lambda operator.
            this.tokens.Add(this.GetOperatorToken(OperatorType.Lambda));

            // Get the body of the expression. This can either be an expression or a statement.
            // If it starts with an opening curly bracket, it's a statement, otherwise it's an expression.
            symbol = this.GetNextSymbol();

            if (symbol.SymbolType == SymbolType.OpenCurlyBracket)
            {
                lambdaExpression.AnonymousFunctionBody = this.GetNextStatement(unsafeCode);
            }
            else
            {
                lambdaExpression.AnonymousFunctionBody = this.GetNextExpression(ExpressionPrecedence.None, unsafeCode);
            }

            // Create the overall token list for the expression.
            Node<CsToken> firstNode = previousTokenNode == null ? this.tokens.First : previousTokenNode.Next;
            lambdaExpression.Tokens = new CsTokenList(this.tokens, firstNode, this.tokens.Last);

            // Get the item's argument list if necessary.
            if (parameters != null && parameters.Count > 0)
            {
                lambdaExpression.AddParameters(parameters);
            }

            // Add a variable for each of the parameters.
            if (lambdaExpression.Parameters != null && lambdaExpression.Parameters.Count > 0)
            {
                // Add a variable for each of the parameters.
                foreach (Parameter parameter in lambdaExpression.Parameters)
                {
                    lambdaExpression.Variables.Add(new Variable(
                        parameter.Type, parameter.Name, VariableModifiers.None, parameter.Location.StartPoint));
                }
            }

            // Return the expression.
            return lambdaExpression;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:83,代码来源:LargeTestFile.cs


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