private static string MakeMethodScopedSynthesizedName(GeneratedNameKind kind, int methodOrdinal, int generation, string methodNameOpt = null, string suffix = null, int uniqueId = -1, bool isTypeName = false) { Debug.Assert(methodOrdinal >= -1); Debug.Assert(generation >= 0); Debug.Assert(uniqueId >= -1); var result = PooledStringBuilder.GetInstance(); var builder = result.Builder; builder.Append('<'); if (methodNameOpt != null) { builder.Append(methodNameOpt); // CLR generally allows names with dots, however some APIs like IMetaDataImport // can only return full type names combined with namespaces. // see: http://msdn.microsoft.com/en-us/library/ms230143.aspx (IMetaDataImport::GetTypeDefProps) // When working with such APIs, names with dots become ambiguous since metadata // consumer cannot figure where namespace ends and actual type name starts. // Therefore it is a good practice to avoid type names with dots. // As a replacement use a character not allowed in C# identifier to avoid conflicts. if (kind.IsTypeName()) { builder.Replace('.', DotReplacementInTypeNames); } } builder.Append('>'); builder.Append((char)kind); if (suffix != null || methodOrdinal >= 0 || uniqueId >= 0) { builder.Append(SuffixSeparator); builder.Append(suffix); if (methodOrdinal >= 0) { builder.Append(methodOrdinal); if (generation > 0) { builder.Append(GenerationSeparator); builder.Append(generation); } } if (uniqueId >= 0) { if (methodOrdinal >= 0) { builder.Append(IdSeparator); } builder.Append(uniqueId); } } return(result.ToStringAndFree()); }
private static string MakeMethodScopedSynthesizedName( GeneratedNameKind kind, int methodOrdinal, int methodGeneration, string methodNameOpt = null, string suffix = null, char suffixTerminator = '\0', int entityOrdinal = -1, int entityGeneration = -1) { StringBuilder builder = new StringBuilder(); builder.Append('<'); if (methodNameOpt != null) { builder.Append(methodNameOpt); if (kind.IsTypeName()) { builder.Replace('.', '-'); } } builder.Append('>'); builder.Append((char)kind); if (suffix != null || methodOrdinal >= 0 || entityOrdinal >= 0) { builder.Append("__"); builder.Append(suffix); if (suffixTerminator != char.MinValue) { builder.Append(suffixTerminator); } if (methodOrdinal >= 0) { builder.Append(methodOrdinal); GeneratedNames.AppendOptionalGeneration(builder, methodGeneration); } if (entityOrdinal >= 0) { if (methodOrdinal >= 0) { builder.Append('_'); } builder.Append(entityOrdinal); GeneratedNames.AppendOptionalGeneration(builder, entityGeneration); } } return(builder.ToString()); }
private static string MakeMethodScopedSynthesizedName( GeneratedNameKind kind, int methodOrdinal, int methodGeneration, string methodNameOpt = null, string suffix = null, int entityOrdinal = -1, int entityGeneration = -1, bool isTypeName = false) { Debug.Assert(methodOrdinal >= -1); Debug.Assert(methodGeneration >= 0 || methodGeneration == -1 && methodOrdinal == -1); Debug.Assert(entityOrdinal >= -1); Debug.Assert(entityGeneration >= 0 || entityGeneration == -1 && entityOrdinal == -1); Debug.Assert(entityGeneration == -1 || entityGeneration >= methodGeneration); var result = PooledStringBuilder.GetInstance(); var builder = result.Builder; builder.Append('<'); if (methodNameOpt != null) { builder.Append(methodNameOpt); // CLR generally allows names with dots, however some APIs like IMetaDataImport // can only return full type names combined with namespaces. // see: http://msdn.microsoft.com/en-us/library/ms230143.aspx (IMetaDataImport::GetTypeDefProps) // When working with such APIs, names with dots become ambiguous since metadata // consumer cannot figure where namespace ends and actual type name starts. // Therefore it is a good practice to avoid type names with dots. // As a replacement use a character not allowed in C# identifier to avoid conflicts. if (kind.IsTypeName()) { builder.Replace('.', DotReplacementInTypeNames); } } builder.Append('>'); builder.Append((char)kind); if (suffix != null || methodOrdinal >= 0 || entityOrdinal >= 0) { builder.Append(SuffixSeparator); builder.Append(suffix); if (methodOrdinal >= 0) { builder.Append(methodOrdinal); if (methodGeneration > 0) { builder.Append(GenerationSeparator); builder.Append(methodGeneration); } } if (entityOrdinal >= 0) { if (methodOrdinal >= 0) { builder.Append(IdSeparator); } builder.Append(entityOrdinal); if (entityGeneration > 0) { builder.Append(GenerationSeparator); builder.Append(entityGeneration); } } } return result.ToStringAndFree(); }