/// <summary> /// Formats the indexer based on the language specification as a /// collection of syntax tokens. /// </summary> /// <param name="syntax">The syntax class that describes the indexer.</param> /// <returns>The collection of tokens describing the indexer in the language</returns> public SyntaxTokenCollection Format(IndexorSyntax syntax) { SyntaxTokenCollection tokens = new SyntaxTokenCollection(); tokens.AddRange(FormatVisibility(syntax)); tokens.Add(Constants.Space); tokens.AddRange(FormatType(syntax)); tokens.Add(Constants.Space); tokens.Add(FormatIdentifier(syntax)); // Provide the properties to access the indexer, these are // obtained from the get method. MethodSyntax getMethod = new MethodSyntax( _syntax.GetMethod != null ? _syntax.GetMethod : _syntax.SetMethod ); tokens.Add(new SyntaxToken("[", SyntaxTokens.Text)); List <ParameterDetails> parameters = getMethod.GetParameters(); // dont output the last parameter if we are not using the get method as it is the return value... for (int i = 0; i < parameters.Count; i++) { ParameterDetails current = parameters[i]; tokens.AddRange(FormatTypeDetails(current.TypeDetails)); tokens.Add(Constants.Space); tokens.Add(new SyntaxToken(current.Name, SyntaxTokens.Text)); if (i < parameters.Count - 1) { tokens.Add(new SyntaxToken(", ", SyntaxTokens.Text)); } } tokens.Add(new SyntaxToken("]", SyntaxTokens.Text)); tokens.Add(new SyntaxToken(" {", SyntaxTokens.Text)); if (_syntax.GetMethod != null) { tokens.Add(new SyntaxToken("\n\t", SyntaxTokens.Text)); if (syntax.GetVisibility() != syntax.GetGetterVisibility()) { tokens.AddRange(FormatGetVisibility(syntax)); tokens.Add(Constants.Space); } tokens.Add(Constants.KeywordGet); tokens.Add(new SyntaxToken(";", SyntaxTokens.Text)); } if (this._syntax.SetMethod != null) { tokens.Add(new SyntaxToken("\n\t", SyntaxTokens.Text)); if (syntax.GetVisibility() != syntax.GetSetterVisibility()) { tokens.AddRange(FormatSetVisibility(syntax)); tokens.Add(Constants.Space); } tokens.Add(Constants.KeywordSet); tokens.Add(new SyntaxToken(";", SyntaxTokens.Text)); } tokens.Add(new SyntaxToken("\n\t}", SyntaxTokens.Text)); return(tokens); }
public List <SyntaxToken> FormatVisibility(IndexorSyntax syntax) { return(FormatVisibility(syntax.GetVisibility())); }