/// <summary> /// Creates a new <see cref="Signature"/> just like this one, but with a custom function that /// builds a list of parameter associated with each argument. /// </summary> public Signature WithLayout(ParameterLayout layout) { return(new Signature(this.ReturnKind, this._returnType, this._body, this.Declaration, this.CustomReturnType, this._tabularity, this.Parameters, layout, this.IsHidden)); }
private Signature( ReturnTypeKind returnKind, TypeSymbol returnType, string body, FunctionDeclaration declaration, CustomReturnType customReturnType, Tabularity tabularity, IReadOnlyList <Parameter> parameters, ParameterLayout layout = null, bool isHidden = false) { if (returnKind == ReturnTypeKind.Declared && returnType == null) { throw new ArgumentNullException(nameof(returnType)); } if (returnKind == ReturnTypeKind.Computed && !(body != null | declaration != null)) { throw new ArgumentNullException(nameof(body)); } if (returnKind == ReturnTypeKind.Custom && customReturnType == null) { throw new ArgumentNullException(nameof(customReturnType)); } this.ReturnKind = returnKind; this._returnType = returnType; this._body = body; this.Declaration = declaration; this.CustomReturnType = customReturnType; this._tabularity = tabularity; this.Parameters = parameters.ToReadOnly(); this.IsHidden = isHidden; if (returnKind == ReturnTypeKind.Computed && returnType != null && tabularity == Tabularity.Unknown) { this._tabularity = returnType.Tabularity; } int minArgumentCount = 0; int maxArgumentCount = 0; foreach (var p in this.Parameters) { if (p.IsRepeatable) { this.HasRepeatableParameters = true; } if (p.IsOptional) { this.HasOptionalParameters = true; } if (p.ArgumentKind == ArgumentKind.Aggregate) { this.HasAggregateParameters = true; } minArgumentCount += p.MinOccurring; maxArgumentCount += p.MaxOccurring; } this.MinArgumentCount = minArgumentCount; this.MaxArgumentCount = maxArgumentCount; if (layout != null) { this.Layout = layout; } else if (this.HasRepeatableParameters) { this.Layout = ParameterLayouts.Repeating; } else { this.Layout = ParameterLayouts.Fixed; } }