private void FixPropertyNames(PropertyTypeClass propertyClass) { foreach (var prop in propertyClass.Properties) { if (prop.Name.Equals(propertyClass.Name)) { prop.Name += "_"; } } }
private IEnumerable <PropertyTypeClass> Parse(IDictionary <string, PropertySpec> propertySpecs) { var propertyClasses = propertySpecs.Where(x => x.Value.Properties != null).Select(x => { var keyParts = x.Key.Split('.').Reverse().ToArray(); var className = keyParts[0]; string path; string namespaceName; if (keyParts.Length == 1) { namespaceName = string.Join(".", BaseNamespace); path = className; } else { var nameParts = keyParts[1].Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray(); namespaceName = string.Join(".", nameParts.Prepend(BaseNamespace)); var pathParts = nameParts.Append(className).ToArray(); path = Path.Combine(pathParts); } path = Path.ChangeExtension(path, ".cs"); // Fix aliases foreach (var prop in x.Value.Properties) { var aliasName = $"{x.Key.Split(".")[0]}.{prop.Value.ItemType ?? prop.Value.Type}"; if (_aliases.TryGetValue(aliasName, out var aliasType)) { prop.Value.Type = aliasType.Type; prop.Value.ItemType = aliasType.ItemType; prop.Value.PrimitiveType = aliasType.PrimitiveType; prop.Value.PrimitiveItemType = aliasType.PrimitiveItemType; } } var propertyClass = new PropertyTypeClass { Name = className, Namespace = namespaceName, Path = path, Documentation = x.Value.Documentation, Properties = Parse(x.Value.Properties) }; FixPropertyNames(propertyClass); return(propertyClass); }) .OrderBy(x => $"{x.Namespace}.{x.Name}") .ToList(); return(propertyClasses); }
private IEnumerable <PropertyTypeClass> Parse(IDictionary <string, PropertySpec> propertySpecs) { var propertyClasses = propertySpecs.Select(x => { var keyParts = x.Key.Split('.').Reverse().ToArray(); var className = keyParts[0]; string path; string namespaceName; if (keyParts.Length == 1) { namespaceName = string.Join(".", BaseNamespace); path = className; } else { var nameParts = keyParts[1].Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray(); namespaceName = string.Join(".", nameParts.Prepend(BaseNamespace)); var pathParts = nameParts.Append(className).ToArray(); path = Path.Combine(pathParts); } path = Path.ChangeExtension(path, ".cs"); var propertyClass = new PropertyTypeClass { Name = className, Namespace = namespaceName, Path = path, Documentation = x.Value.Documentation, Properties = Parse(x.Value.Properties) }; FixPropertyNames(propertyClass); return(propertyClass); }).ToList(); return(propertyClasses); }
public PropertyTypeTemplate(PropertyTypeClass propertyType) { _propertyTypeField = propertyType; }