private string GenerateProp(TDField field) { return(propTemplate .Replace("%CONV%", GenerateConv(field)) .Replace("%TYPE%", GenerateType(field)) .Replace("%NAME%", field.Name) .Replace("%DESCR%", field.Descr ?? "") .Replace("%PROP%", GeneratePropName(field.Name))); }
private string GenerateConv(TDField field) { var type = GenerateType(field); if (type.StartsWith("Int64")) { return("Converter.Int64"); } return("Converter"); }
private string GenerateType(TDField field) { string type = field.Type.Name; var n = field.Type.Name.Count(c => c == '<'); if (n == 0) { if (field.Type.Base != null && !string.Equals(field.Type.Base.Name, type, StringComparison.OrdinalIgnoreCase)) { type = field.Type.Base.Name + "." + type; } if (builtins.Contains(type)) { return(type); } return(GetTypeName(type)); } int begin = type.LastIndexOf('<'); int end = type.IndexOf('>'); type = type.Substring(begin + 1, end - begin - 1); // O_o if (field.Type.Generic?.Generic?.Generic?.Base != null) // 3rd generic level { if (!string.Equals(field.Type.Generic.Generic.Generic.Base.Name, type, StringComparison.OrdinalIgnoreCase)) { type = field.Type.Generic.Generic.Generic.Base.Name + "." + type; } } else if (field.Type.Generic?.Generic?.Base != null) // 2nd generic level { if (!string.Equals(field.Type.Generic.Generic.Base.Name, type, StringComparison.OrdinalIgnoreCase)) { type = field.Type.Generic.Generic.Base.Name + "." + type; } } else if (field.Type.Generic?.Base != null) // 1st generic level { if (!string.Equals(field.Type.Generic.Base.Name, type, StringComparison.OrdinalIgnoreCase)) { type = field.Type.Generic.Base.Name + "." + type; } } bool builtin = builtins.Contains(type); for (int i = 0; i < n; i++) { type += "[]"; } return(builtin ? type : GetTypeName(type)); }