/// <summary> /// Get the specified parameters as a descriptive string. /// </summary> internal static string GetParametersAsString(string tokenStart, string tokenend, ChildList <ParameterDecl> parameterDecls) { string result = tokenStart; if (parameterDecls != null && parameterDecls.Count > 0) { bool isFirst = true; foreach (ParameterDecl parameter in parameterDecls) { if (!isFirst) { result += ", "; } if (parameter.Modifier != ParameterModifier.None) { result += ParameterDecl.ParameterModifierToString(parameter.Modifier) + " "; } // Don't use GetDescription() on the Type, because we don't want any ShowParentTypes here result += parameter.Type.AsText(RenderFlags.Description) + " " + parameter.Name; isFirst = false; } } result += tokenend; return(result); }
protected void ParseParameters(Parser parser) { // Parse the parameter declarations bool isEndFirstOnLine; _parameters = ParameterDecl.ParseList(parser, this, ParseTokenStart, ParseTokenEnd, false, out isEndFirstOnLine); IsEndFirstOnLine = isEndFirstOnLine; }
/// <summary> /// Get the declaring type of the referenced constructor. /// </summary> public override TypeRefBase GetDeclaringType() { // Do a special check for a generated constructor for an external delegate type (see TypeRef.GetConstructors()) ConstructorDecl constructorDecl = _reference as ConstructorDecl; if (constructorDecl != null && constructorDecl.Parent == null && constructorDecl.IsGenerated) { ChildList <ParameterDecl> parameters = constructorDecl.Parameters; if (parameters.Count == 1) { ParameterDecl parameterDecl = parameters[0]; if (parameterDecl.Name == DelegateDecl.DelegateConstructorParameterName) { return(parameterDecl.Type as TypeRef); } } } return(base.GetDeclaringType()); }
protected DelegateDecl(Parser parser, CodeObject parent) : base(parser, parent) { MoveComments(parser.LastToken); // Get any comments before 'class' parser.NextToken(); // Move past 'delegate' SetField(ref _returnType, Expression.Parse(parser, this, true), true); // Parse the return type ParseNameTypeParameters(parser); // Parse the name and any optional type parameters // Parse the parameter declarations bool isEndFirstOnLine; _parameters = ParameterDecl.ParseList(parser, this, ParseTokenStart, ParseTokenEnd, false, out isEndFirstOnLine); IsEndFirstOnLine = isEndFirstOnLine; ParseModifiersAndAnnotations(parser); // Parse any attributes and/or modifiers ParseConstraintClauses(parser); // Parse any constraint clauses ParseTerminator(parser); GenerateMethods(); // Generate invoke methods and constructor }
protected AnonymousMethod(Parser parser, CodeObject parent) : base(parser, parent) { Token startingToken = parser.Token; // Get the object starting token parser.NextToken(); // Move past 'delegate' // Parse the parameter declarations bool isEndFirstOnLine; _parameters = ParameterDecl.ParseList(parser, this, ParseTokenStart, ParseTokenEnd, true, out isEndFirstOnLine); IsEndFirstOnLine = isEndFirstOnLine; // If the body is indented less than the parent object, set the NoIndentation flag to prevent it from // being formatted relative to the parent object. if (parser.CurrentTokenIndentedLessThan(startingToken)) { SetFormatFlag(FormatFlags.NoIndentation, true); } new Block(out _body, parser, this, true); // Parse the body }
protected IndexerDecl(Parser parser, CodeObject parent) : base(parser, parent, false) { // Get the ThisRef or Dot expression. If it's a Dot, replace the ThisRef with an UnresolvedThisRef, // which has an internal name of "Item", but displays as "this". Expression expression = parser.RemoveLastUnusedExpression(); SetField(ref _name, CheckUnresolvedThisRef(expression), false); Expression leftExpression = (expression is BinaryOperator ? ((BinaryOperator)expression).Left : expression); _lineNumber = leftExpression.LineNumber; _columnNumber = (ushort)leftExpression.ColumnNumber; ParseTypeModifiersAnnotations(parser); // Parse type and any modifiers and/or attributes // Parse the parameter declarations bool isEndFirstOnLine; _parameters = ParameterDecl.ParseList(parser, this, ParseTokenStart, ParseTokenEnd, false, out isEndFirstOnLine); IsEndFirstOnLine = isEndFirstOnLine; new Block(out _body, parser, this, true); // Parse the body }
public static void AsTextParameterInfo(CodeWriter writer, ParameterInfo parameterInfo, RenderFlags flags) { RenderFlags passFlags = flags & ~RenderFlags.Description; Attribute.AsTextAttributes(writer, parameterInfo); ParameterModifier modifier = GetParameterModifier(parameterInfo); if (modifier != ParameterModifier.None) { writer.Write(ParameterDecl.ParameterModifierToString(modifier) + " "); } Type parameterType = parameterInfo.ParameterType; if (parameterType.IsByRef) { // Dereference (remove the trailing '&') if it's a reference type parameterType = parameterType.GetElementType(); } TypeRefBase.AsTextType(writer, parameterType, passFlags); writer.Write(" " + parameterInfo.Name); }
/// <summary> /// Create a <see cref="DocParamRef"/>. /// </summary> public DocParamRef(ParameterDecl parameterDecl) : base(parameterDecl.CreateRef(), (string)null) { }
/// <summary> /// Create a <see cref="ConversionOperatorDecl"/>. /// </summary> public ConversionOperatorDecl(Expression destinationType, Modifiers modifiers, ParameterDecl parameter) : base(GetInternalName(modifiers), destinationType, modifiers, new[] { parameter }) { }
/// <summary> /// Parse a list of parameters. /// </summary> public static ChildList <ParameterDecl> ParseList(Parser parser, CodeObject parent, string parseTokenStart, string parseTokenEnd, bool forceEmpty, out bool isEndFirstOnLine) { ChildList <ParameterDecl> parameterDecls = null; isEndFirstOnLine = false; if (parser.TokenText == parseTokenStart) { Token lastToken = parser.Token; parser.NextToken(); // Move past '(' or '[' // Force an empty collection (vs null) if the flag is set if (forceEmpty) { parameterDecls = new ChildList <ParameterDecl>(parent); } // Create a string of possible terminators (assuming 1 char terminators for now) string terminators = parseTokenEnd + ParseTokenTerminator + Block.ParseTokenStart + Block.ParseTokenEnd + Index.ParseTokenEnd; while (parser.TokenText != null && (parser.TokenText.Length != 1 || terminators.IndexOf(parser.TokenText[0]) < 0)) { ParameterDecl parameterDecl = new ParameterDecl(parser, parent, parseTokenEnd); // Move any preceeding comments to the current ParameterDecl parameterDecl.MoveComments(lastToken); if (parameterDecls == null) { parameterDecls = new ChildList <ParameterDecl>(parent); } parameterDecls.Add(parameterDecl); lastToken = parser.Token; if (parser.TokenText == ParseTokenSeparator) { parser.NextToken(); // Move past ',' // Associate any EOL comment on the ',' to the last ParameterDecl parameterDecl.MoveEOLComment(lastToken, false, false); // Move any remaining regular comments as Post comments, if on a line by themselves if (parser.Token.IsFirstOnLine) { parameterDecl.MoveCommentsAsPost(lastToken); } } } if (parent.ParseExpectedToken(parser, parseTokenEnd)) // Move past ')' or ']' { isEndFirstOnLine = parser.LastToken.IsFirstOnLine; if (parameterDecls == null || parameterDecls.Count == 0) { parent.MoveAllComments(lastToken, false, false, AnnotationFlags.IsInfix1); } parent.MoveEOLComment(parser.LastToken); // Associate any skipped EOL comment with the parent } } return(parameterDecls); }
/// <summary> /// Create a <see cref="BooleanOperatorDecl"/>. /// </summary> public BooleanOperatorDecl(string symbol, Modifiers modifiers, ParameterDecl parameter) : base(symbol, (TypeRef)TypeRef.BoolRef.Clone(), modifiers, new[] { parameter }) { }
/// <summary> /// Create a <see cref="ParameterRef"/>. /// </summary> public ParameterRef(ParameterDecl parameterDecl) : base(parameterDecl, false) { }
/// <summary> /// Create a <see cref="ParameterRef"/>. /// </summary> public ParameterRef(ParameterDecl parameterDecl, bool isFirstOnLine) : base(parameterDecl, isFirstOnLine) { }
/// <summary> /// Add one or more <see cref="ParameterDecl"/>s. /// </summary> public void AddParameter(ParameterDecl parameterDecl) { CreateParameters().Add(parameterDecl); }
/// <summary> /// Create a <see cref="DocPara"/>. /// </summary> public DocParam(ParameterDecl parameterDecl, params DocComment[] docComments) : base(parameterDecl.CreateRef(), docComments) { }
/// <summary> /// Create a <see cref="DocPara"/>. /// </summary> public DocParam(ParameterDecl parameterDecl, string text) : base(parameterDecl.CreateRef(), text) { }