internal static string ToKeyString(this TypeSymbol typeSymbol) { var sb = new StringBuilder(); var containingNamespaceOrType = typeSymbol.ContainingNamespaceOrType(); if (containingNamespaceOrType != null) { if (containingNamespaceOrType.IsType) { sb.Append(((TypeSymbol)containingNamespaceOrType).ToKeyString()); } else { sb.Append(containingNamespaceOrType); sb.Append("."); } } sb.Append(typeSymbol.MetadataName); return(sb.ToString()); }
internal static string ToKeyString(this TypeSymbol typeSymbol, bool metadata = true) { var sb = new StringBuilder(); var containingNamespaceOrType = typeSymbol.ContainingNamespaceOrType(); if (containingNamespaceOrType != null) { if (containingNamespaceOrType.IsType) { sb.Append(((TypeSymbol)containingNamespaceOrType).ToKeyString()); } else { sb.Append(containingNamespaceOrType); sb.Append("."); } } if (metadata) { if (string.IsNullOrWhiteSpace(typeSymbol.MetadataName)) { sb.Append(typeSymbol); } else { sb.Append(typeSymbol.MetadataName); } } else { var namedTypeSymbol = typeSymbol as NamedTypeSymbol; if (typeSymbol.IsAnonymousType()) { sb.Append("<>f__AnonymousType"); if (typeSymbol.IsAnonymousType) { var parameterTypes = ((NamedTypeSymbol)typeSymbol).Constructors.First().ParameterTypes; sb.Append(parameterTypes.Length); sb.Append("<"); var any = false; foreach (var typeArgument in parameterTypes) { if (any) { sb.Append(", "); } sb.Append(typeArgument.ToKeyString(metadata)); any = true; } sb.Append(">"); } else { sb.Append(namedTypeSymbol.TypeArguments.Length); } } else { if (string.IsNullOrWhiteSpace(typeSymbol.Name)) { sb.Append(typeSymbol); } else { sb.Append(typeSymbol.Name); } } if (namedTypeSymbol != null) { if (namedTypeSymbol.Arity > 0) { sb.Append("<"); var any = false; foreach (var typeArgument in namedTypeSymbol.TypeArguments) { if (any) { sb.Append(", "); } sb.Append(typeArgument.ToKeyString(metadata)); any = true; } sb.Append(">"); } } } return(sb.ToString()); }