private void FixStutteringTypeNames(CodeModelGo cmg) { // Trim the package name from exported types; append a suitable qualifier, if needed, to avoid conflicts. var exportedTypes = new HashSet <object>(); exportedTypes.UnionWith(cmg.EnumTypes); exportedTypes.UnionWith(cmg.Methods); exportedTypes.UnionWith(cmg.ModelTypes); var stutteringTypes = exportedTypes .Where(exported => (exported is IModelType && (exported as IModelType).Name.FixedValue.StartsWith(cmg.Namespace, StringComparison.OrdinalIgnoreCase)) || (exported is Method && (exported as Method).Name.FixedValue.StartsWith(cmg.Namespace, StringComparison.OrdinalIgnoreCase))); if (stutteringTypes.Any()) { Logger.Instance.Log(Category.Warning, string.Format(CultureInfo.InvariantCulture, Resources.NamesStutter, stutteringTypes.Count())); stutteringTypes.ForEach(exported => { var name = exported is IModelType ? (exported as IModelType).Name : (exported as Method).Name; Logger.Instance.Log(Category.Warning, string.Format(CultureInfo.InvariantCulture, Resources.StutteringName, name)); name = name.FixedValue.TrimPackageName(cmg.Namespace); var nameInUse = exportedTypes .Any(et => (et is IModelType && (et as IModelType).Name.Equals(name)) || (et is Method && (et as Method).Name.Equals(name))); if (exported is EnumType) { (exported as EnumType).Name.FixedValue = CodeNamerGo.AttachTypeName(name, cmg.Namespace, nameInUse, "Enum"); } else if (exported is CompositeType) { (exported as CompositeType).Name.FixedValue = CodeNamerGo.AttachTypeName(name, cmg.Namespace, nameInUse, "Type"); } else if (exported is Method) { (exported as Method).Name = CodeNamerGo.AttachTypeName(name, cmg.Namespace, nameInUse, "Method"); } }); } }
private static void FixStutteringTypeNames(CodeModelGo cmg) { // Trim the package name from exported types; append a suitable qualifier, if needed, to avoid conflicts. var exportedTypes = new HashSet <object>(); exportedTypes.UnionWith(cmg.EnumTypes); exportedTypes.UnionWith(cmg.Methods); exportedTypes.UnionWith(cmg.ModelTypes); var stutteringTypes = exportedTypes .Where(exported => (exported is IModelType modelType && modelType.Name.FixedValue.StartsWith(cmg.Namespace, StringComparison.OrdinalIgnoreCase)) || (exported is Method method && method.Name.FixedValue.StartsWith(cmg.Namespace, StringComparison.OrdinalIgnoreCase))); if (stutteringTypes.Any()) { stutteringTypes.ForEach(exported => { var name = exported is IModelType type ? type.Name : ((Method)exported).Name; name = name.Value.TrimPackageName(cmg.Namespace); var nameInUse = exportedTypes .Any(et => (et is IModelType modeltype && modeltype.Name.Equals(name)) || (et is Method methodType && methodType.Name.Equals(name))); if (exported is EnumType enumType) { enumType.Name.Value = CodeNamerGo.AttachTypeName(name, cmg.Namespace, nameInUse, "Enum"); } else if (exported is CompositeType compositeType) { compositeType.Name.Value = CodeNamerGo.AttachTypeName(name, cmg.Namespace, nameInUse, "Type"); } else if (exported is Method methodType) { methodType.Name.Value = CodeNamerGo.AttachTypeName(name, cmg.Namespace, nameInUse, "Method"); } }); } }