public AddTypeParameter ( |
||
typeParameter | Type paramater to add. | |
return | void |
/// <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; }
/// <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 { bool expression = NextChar == CSharpSymbol.Assignment; if (expression) { var expressionHead = new[] { CSharpSymbol.ExpressionBodyArrow1, CSharpSymbol.ExpressionBodyArrow2 }; // lucky for us, expressions can only have one statement (unlike expression lambdas), // therefore we must have text like this "=> followed.by.a.statement;" which ParseOptionalAssignment will automatically trim to "followed.by.a.statement" method.BodyText = this.ParseOptionalExpression(expressionHead); method.HasExpressionBody = true; if (string.IsNullOrEmpty(method.BodyText)) { // is expression, but no suitable body found this.OnParseError("Unexpected end of method. Expected " + new string(expressionHead) + " or a method body."); } } else { method.BodyText = this.ParseBlock(true, method); } } return method; }