本文整理汇总了C#中CsTokenList.Trim方法的典型用法代码示例。如果您正苦于以下问题:C# CsTokenList.Trim方法的具体用法?C# CsTokenList.Trim怎么用?C# CsTokenList.Trim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsTokenList
的用法示例。
在下文中一共展示了CsTokenList.Trim方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseParameterList
//.........这里部分代码省略.........
// If there is a parameter modifier, get it.
if (symbol.SymbolType == SymbolType.Ref)
{
this.tokens.Add(this.GetToken(CsTokenType.Ref, SymbolType.Ref, parameterReference));
modifiers |= ParameterModifiers.Ref;
}
else if (symbol.SymbolType == SymbolType.Out)
{
this.tokens.Add(this.GetToken(CsTokenType.Out, SymbolType.Out, parameterReference));
modifiers |= ParameterModifiers.Out;
}
else if (symbol.SymbolType == SymbolType.Params)
{
this.tokens.Add(this.GetToken(CsTokenType.Params, SymbolType.Params, parameterReference));
modifiers |= ParameterModifiers.Params;
}
else if (symbol.SymbolType == SymbolType.This)
{
// The this keyword indicates that this is an extension method. This is only allowed if
// both of the following are true:
// 1. This must be the first parameter.
// 2. The element must be a static method.
if (parameters.Count == 0 && staticMethod)
{
this.tokens.Add(this.GetToken(CsTokenType.This, SymbolType.This, parameterReference));
modifiers |= ParameterModifiers.This;
}
}
// Get the parameter type.
TypeToken parameterType = this.GetTypeToken(parameterReference, unsafeCode, true);
CsToken parameterName = null;
if (parameterType.Text.Equals("__arglist", StringComparison.Ordinal))
{
// When the parameterType is __arglist, this means that there is actually no parameter type at
// all, and the parameter name should be set to the __arglist token.
parameterName = parameterType.ChildTokens.First.Value;
parameterType = null;
parameterName.ParentRef = parameterReference;
this.tokens.Add(parameterName);
}
else
{
this.tokens.Add(parameterType);
// Get the parameter name.
parameterName = this.GetToken(CsTokenType.Other, SymbolType.Other, parameterReference);
this.tokens.Add(parameterName);
}
// Get the optional default value for the parameter.
Expression defaultArgument = null;
symbol = this.GetNextSymbol(parameterReference);
if (symbol.SymbolType == SymbolType.Equals)
{
this.tokens.Add(this.GetOperatorToken(OperatorType.Equals, parameterReference));
// Get the default value expression.
defaultArgument = this.GetNextExpression(ExpressionPrecedence.None, parameterReference, unsafeCode);
}
// Create the list of tokens comprising the parameter, and trim any whitespace off the beginning and end.
var tokenList = new CsTokenList(this.tokens, previousToken.Next, this.tokens.Last);
tokenList.Trim();
var parameter = new Parameter(
parameterType,
parameterName.Text,
elementReference,
modifiers,
defaultArgument,
parameterType == null ? parameterName.Location : CodeLocation.Join(parameterType.Location, parameterName.Location),
tokenList,
parameterType == null ? parameterName.Generated : parameterType.Generated || parameterName.Generated);
parameterReference.Target = parameter;
parameters.Add(parameter);
// If the next symbol, is a comma, get the next parameter.
symbol = this.GetNextSymbol(elementReference);
if (symbol.SymbolType == SymbolType.Comma)
{
this.tokens.Add(this.GetToken(CsTokenType.Comma, SymbolType.Comma, elementReference));
symbol = this.GetNextSymbol(elementReference);
}
}
// Get the closing bracket.
Bracket closingParenthesis = this.GetBracketToken(closingBracketTokenType, closingBracketType, elementReference);
Node<CsToken> closingParenthesisNode = this.tokens.InsertLast(closingParenthesis);
openingParenthesis.MatchingBracketNode = closingParenthesisNode;
closingParenthesis.MatchingBracketNode = openingParenthesisNode;
// Return the parameters as a read-only collection.
return parameters.ToArray();
}
示例2: GetArgumentList
/// <summary>
/// Reads the argument list for a method invocation expression.
/// </summary>
/// <param name="closingSymbol">The symbol that closes the argument list.</param>
/// <param name="parentReference">The parent code part.</param>
/// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
/// <returns>Returns the list of arguments in the method invocation.</returns>
private IList<Argument> GetArgumentList(SymbolType closingSymbol, Reference<ICodePart> parentReference, bool unsafeCode)
{
Param.AssertNotNull(closingSymbol, "closingSymbol");
Param.AssertNotNull(parentReference, "parentReference");
Param.Ignore(unsafeCode);
List<Argument> arguments = new List<Argument>();
while (true)
{
// Save the current last token.
Node<CsToken> previousTokenNode = this.tokens.Last;
// Move to the next code token.
Symbol firstSymbol = this.GetNextSymbol(parentReference);
if (firstSymbol.SymbolType == closingSymbol)
{
break;
}
var argumentReference = new Reference<ICodePart>();
if (firstSymbol.SymbolType != SymbolType.Comma)
{
// Gather the parameter name label if it exists.
CsToken argumentName = null;
if (firstSymbol.SymbolType == SymbolType.Other)
{
// Look at the next symbol after the label.
int index = this.GetNextCodeSymbolIndex(2);
if (index >= 0)
{
Symbol colon = this.symbols.Peek(index);
if (colon != null && colon.SymbolType == SymbolType.Colon)
{
// This is an argument name label. Add the name label and the colon.
argumentName = this.GetToken(CsTokenType.Other, SymbolType.Other, argumentReference);
this.tokens.Add(argumentName);
// The next symbol must be the colon.
this.tokens.Add(this.GetToken(CsTokenType.LabelColon, SymbolType.Colon, argumentReference));
}
}
}
// Gather the argument modifiers.
ParameterModifiers modifiers = ParameterModifiers.None;
int i = this.GetNextCodeSymbolIndex(1);
if (i >= 0)
{
Symbol symbol = this.symbols.Peek(i);
if (symbol.SymbolType == SymbolType.Ref)
{
this.tokens.Add(this.GetToken(CsTokenType.Ref, SymbolType.Ref, argumentReference));
modifiers = ParameterModifiers.Ref;
}
else if (symbol.SymbolType == SymbolType.Out)
{
this.tokens.Add(this.GetToken(CsTokenType.Out, SymbolType.Out, argumentReference));
modifiers = ParameterModifiers.Out;
}
else if (symbol.SymbolType == SymbolType.Params)
{
this.tokens.Add(this.GetToken(CsTokenType.Params, SymbolType.Params, argumentReference));
modifiers = ParameterModifiers.Params;
}
}
// The argument body expression must come next.
Expression argumentExpression = this.GetNextExpression(ExpressionPrecedence.None, argumentReference, unsafeCode);
// Create the collection of tokens that form the argument, and strip off whitesace from the beginning and end.
var argumentTokenList = new CsTokenList(this.tokens, previousTokenNode.Next, this.tokens.Last);
argumentTokenList.Trim(CsTokenType.EndOfLine, CsTokenType.WhiteSpace);
// Create and add the argument.
var argument = new Argument(
argumentName,
modifiers,
argumentExpression,
CodeLocation.Join(firstSymbol.Location, argumentExpression.Location),
parentReference,
argumentTokenList,
this.symbols.Generated);
argumentReference.Target = argument;
arguments.Add(argument);
}
// If the next symbol is a comma, add the comma and proceed.
//.........这里部分代码省略.........