private ResourceClass Parse(string type, ResourceSpec resourceSpec) { var nameParts = type.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries).Skip(1); var className = nameParts.Last(); var namespaceName = string.Join(".", nameParts.Prepend(BaseNamespace)); var path = Path.ChangeExtension(Path.Combine(Path.Combine(nameParts.ToArray()), className + "Resource"), ".cs"); // Fix aliases foreach (var prop in resourceSpec.Properties) { var aliasName = $"{type}.{prop.Value.ItemType ?? prop.Value.Type}"; if (_aliases.TryGetValue(aliasName, out var aliasType)) { if (prop.Value.ItemType != null) { prop.Value.ItemType = aliasType.Type; prop.Value.PrimitiveItemType = aliasType.PrimitiveType; } else { prop.Value.Type = aliasType.Type; prop.Value.ItemType = aliasType.ItemType; prop.Value.PrimitiveType = aliasType.PrimitiveType; prop.Value.PrimitiveItemType = aliasType.PrimitiveItemType; } } } var resourceClass = new ResourceClass { Type = type, Name = className, Namespace = namespaceName, Path = path, Documentation = resourceSpec.Documentation, Attributes = Parse(resourceSpec.Attributes), Properties = Parse(resourceSpec.Properties) }; return(resourceClass); }
private IEnumerable <ResourceClass> Parse(IDictionary <string, ResourceSpec> resourceSpecs) { var resourceClasses = resourceSpecs.Select(x => { var nameParts = x.Key.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries).Skip(1); var className = nameParts.Last(); var namespaceName = string.Join(".", nameParts.Prepend(BaseNamespace)); var path = Path.ChangeExtension(Path.Combine(Path.Combine(nameParts.ToArray()), className + "Resource"), ".cs"); var resourceClass = new ResourceClass { Type = x.Key, Name = className, Namespace = namespaceName, Path = path, Documentation = x.Value.Documentation, Attributes = Parse(x.Value.Attributes), Properties = Parse(x.Value.Properties) }; return(resourceClass); }).ToList(); return(resourceClasses); }
public ResourceTypeTemplate(ResourceClass resource) { _resourceField = resource; }