/// <summary>
/// Parses a method.
/// </summary>
/// <param name="memberName">Member name.</param>
/// <param name="access">Code access.</param>
/// <param name="memberAttributes">Member attributes.</param>
/// <param name="returnType">Return type.</param>
/// <param name="isOperator">Whether or not the method is an operator.</param>
/// <param name="operatorType">Type of the operator.</param>
/// <returns>Method code element.</returns>
private MethodElement ParseMethod(
string memberName,
CodeAccess access,
MemberModifiers memberAttributes,
string returnType,
bool isOperator,
OperatorType operatorType)
{
MethodElement method = new MethodElement();
method.Name = memberName;
method.Access = access;
method.Type = returnType;
method.MemberModifiers = memberAttributes;
method.IsOperator = isOperator;
method.OperatorType = operatorType;
if (isOperator &&
(operatorType == OperatorType.Implicit || operatorType == OperatorType.Explicit))
{
method.Type = memberName;
method.Name = null;
}
int genericIndex = memberName.LastIndexOf(CSharpSymbol.BeginGeneric);
int lastQualifierIndex = memberName.LastIndexOf(CSharpSymbol.AliasQualifier);
bool isGeneric = !isOperator &&
(genericIndex >= 0 && genericIndex < memberName.Length - 1 &&
(lastQualifierIndex < 0 || lastQualifierIndex < genericIndex));
if (isGeneric)
{
method.Name = memberName.Substring(0, genericIndex);
string typeParameterString = memberName.TrimEnd(CSharpSymbol.EndGeneric).Substring(
genericIndex + 1);
string[] typeParameterNames = typeParameterString.Split(
new char[] { CSharpSymbol.AliasSeparator, ' ' },
StringSplitOptions.RemoveEmptyEntries);
foreach (string typeParameterName in typeParameterNames)
{
TypeParameter typeParameter = new TypeParameter();
typeParameter.Name = typeParameterName;
method.AddTypeParameter(typeParameter);
}
}
method.Parameters = this.ParseParameters();
if (isGeneric)
{
ParseTypeParameterConstraints(method);
}
EatWhiteSpace();
bool endOfStatement = NextChar == CSharpSymbol.EndOfStatement;
if (endOfStatement)
{
TryReadChar();
method.BodyText = null;
}
else
{
method.BodyText = this.ParseBlock(true, method);
}
return method;
}