internal static string ToKeyString(this MethodSymbol methodSymbol) { var sb = new StringBuilder(); var containingNamespaceOrType = methodSymbol.ContainingNamespaceOrType(); if (containingNamespaceOrType != null) { sb.Append(((TypeSymbol)containingNamespaceOrType).ToKeyString(false)); sb.Append("."); } sb.Append(methodSymbol.Name); if (methodSymbol.IsGenericMethod) { sb.Append("<"); sb.Append(string.Join(",", methodSymbol.TypeParameters.OfType <TypeSymbol>().Select(t => t.ToKeyString(false)))); sb.Append(">"); } sb.Append("("); var any = false; if (methodSymbol.ParameterCount > 0) { foreach (var parameter in methodSymbol.Parameters) { if (any) { sb.Append(", "); } if (parameter.RefKind.HasFlag(RefKind.Out)) { sb.Append("out "); } if (parameter.RefKind.HasFlag(RefKind.Ref)) { sb.Append("ref "); } sb.Append(parameter.Type.ToKeyString(false)); any = true; } } if (any && methodSymbol.IsVararg) { sb.Append(", "); sb.Append("__argList"); } sb.Append(")"); sb.Append(" : "); sb.Append(methodSymbol.ReturnType.ToKeyString(false)); return(sb.ToString()); }
private static int SequenceNumber(MethodSymbol method) { // return a unique sequence number for the async implementation class that is independent of the compilation state. int count = 0; foreach (var m in method.ContainingNamespaceOrType().GetMembers(method.Name)) { count++; if (method == m) { return(count); } } // It is possible we did not find any such members, e.g. for methods that result from the translation of // async lambdas. In that case the method has already been uniquely named, so there is no need to // produce a unique sequence number for the corresponding class, which already includes the (unique) method name. return(count); }