public static string GenerateNewCode(string[] duckTypes, string name, System.Collections.Immutable.ImmutableArray <ITypeParameterSymbol> typeParameters, System.Collections.Immutable.ImmutableArray <ITypeSymbol> typeArguments, TypeParameterListSyntax typeParameterList, SyntaxList <AttributeListSyntax> attributeLists, Func <CSharpSyntaxNode, string, IEnumerable <TypeParameterSyntax>, IEnumerable <AttributeListSyntax>, CSharpSyntaxNode> withDeclarationInfo, CSharpSyntaxNode ogNode, Dictionary <string, List <CSharpSyntaxNode> > newNodes) { var newName = $"GENERATED_{name}_{typeArguments.ListToString("_")}"; var newTypeParams = typeParameterList.Parameters.Where(p => !duckTypes.Contains(p.Identifier.ToString())); var newAttrLists = attributeLists. Select(list => AttributeList(SeparatedList(list.Attributes.Where(attr => attr.Name.ToString() != "DuckTypeAttribute" && attr.Name.ToString() != "DuckType")))). Where(list => list.Attributes.Any()); var newNode = withDeclarationInfo(ogNode, newName, newTypeParams, newAttrLists); var duckToInfer = typeParameters.Zip(typeArguments). ToDictionary(kv => kv.First.ToString(), kv => kv.Second.ToString()); newNode = newNode.ReplaceNodes( newNode.DescendantNodes().OfType <TypeSyntax>(), (_, n) => duckToInfer.TryGetValue(n.ToString(), out var infer) ? ParseTypeName(infer).WithTriviaFrom(n) : n); var ogNodeStr = ogNode.ToString(); newNodes.TryAdd(ogNodeStr, new List <CSharpSyntaxNode>()); newNodes[ogNodeStr].Add(newNode); return(newName); }
/// <summary> /// Adds the specified items to the end of the array. /// </summary> /// <param name="items">The items.</param> public void AddRange<TDerived>(ImmutableArray<TDerived>.Builder items) where TDerived : T { Requires.NotNull(items, "items"); this.AddRange(items.elements, items.Count); }
/// <summary> /// Adds the specified items to the end of the array. /// </summary> /// <param name="items">The items.</param> public void AddRange(ImmutableArray<T> items) { this.AddRange(items, items.Length); }
/// <summary> /// Initializes a new instance of the <see cref="ImmutableArrayBuilderDebuggerProxy{T}"/> class. /// </summary> /// <param name="builder">The collection to display in the debugger</param> public ImmutableArrayBuilderDebuggerProxy(ImmutableArray <T> .Builder builder) { Requires.NotNull(builder, nameof(builder)); _builder = builder; }