diff --git a/PortaCapena.OdooJsonRpcClient/Converters/OdooModelMapper.cs b/PortaCapena.OdooJsonRpcClient/Converters/OdooModelMapper.cs index 748999e..91b2e94 100644 --- a/PortaCapena.OdooJsonRpcClient/Converters/OdooModelMapper.cs +++ b/PortaCapena.OdooJsonRpcClient/Converters/OdooModelMapper.cs @@ -97,13 +97,17 @@ public static bool ConverOdooPropertyToDotNet(Type dotnetType, JToken value, out public static string GetDotNetModel(string tableName, Dictionary properties, bool addSummary = true) { + var existing = new Dictionary(); + var builder = new StringBuilder(); builder.AppendLine($"[OdooTableName(\"{tableName}\")]"); builder.AppendLine($"[JsonConverter(typeof({nameof(OdooModelConverter)}))]"); - builder.AppendLine($"public class {ConvertOdooNameToDotNet(tableName)}{OdooModelSuffix} : IOdooModel"); + builder.AppendLine($"public partial class {ConvertOdooNameToDotNet(tableName, existing)}{OdooModelSuffix} : IOdooModel"); builder.AppendLine("{"); - foreach (var property in properties) + + existing.Clear(); + foreach (var property in properties.OrderBy(p => p.Value.Name)) { builder.AppendLine(string.Empty); @@ -124,7 +128,7 @@ public static string GetDotNetModel(string tableName, Dictionary property, string tableName) + + public static string ConvertToDotNetTypeName(KeyValuePair property, string tableName) { switch (property.Value.PropertyValueType) { @@ -172,40 +181,40 @@ public static string ConvertToDotNetPropertyTypeName(KeyValuePair existing = null) { - odooName = odooName.Replace("+", "Plus"); var odooNameCleaned = Regex.Replace(odooName, "[^A-Za-z0-9-]", "_"); - var dotnetKeys = odooNameCleaned.Split('_', '-', '.', ',', ' ', ':', ';', '/', '\\', '*', '+', '(', ')', '[', ']').Select(x => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(x)); - return string.Join(string.Empty, dotnetKeys); + var dotnetKeys = odooNameCleaned + .Split('_', '-', '.', ',', ' ', ':', ';', '/', '\\', '*', '+', '(', ')', '[', ']') + .Select(x => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(x)) + .Where(x => !string.IsNullOrEmpty(x)) + .ToList(); + if (dotnetKeys.Count == 0) + dotnetKeys.Add("None"); + var result = string.Join(string.Empty, dotnetKeys); + + if (existing == null) existing = new Dictionary(); + + int i = 1; + string dedupResult; + do + { + dedupResult = $"{result}{(i < 2 ? "" : i.ToString())}"; + i++; + } while (existing.ContainsKey(dedupResult)); + + existing[dedupResult] = true; + return dedupResult; } public static object ConvertToDotNetEnum(Type type, JToken value)