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