diff --git a/YangParser/Generator/YangGenerator.cs b/YangParser/Generator/YangGenerator.cs index e1a6ffa..540fe87 100644 --- a/YangParser/Generator/YangGenerator.cs +++ b/YangParser/Generator/YangGenerator.cs @@ -37,16 +37,18 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var yangFiles = context.AdditionalTextsProvider.Where(text => text.Path.EndsWith(".yang")); var parsed = yangFiles.Select((p, _) => Parse(p)); var model = parsed.Select((p, _) => MakeSemanticModel(p)); - context.RegisterSourceOutput(model.Collect(), MakeClasses); + var combined = context.CompilationProvider.Combine(model.Collect()); + context.RegisterSourceOutput(combined, MakeClasses); } - private void MakeClasses(SourceProductionContext context, ImmutableArray> models) + private void MakeClasses(SourceProductionContext context, + (Compilation compilation, ImmutableArray> models) data) { try { Dictionary topLevels = new(); Dictionary modules = new(); - foreach (var model in models) + foreach (var model in data.models) { if (!model.Success) { @@ -74,7 +76,7 @@ private void MakeClasses(SourceProductionContext context, ImmutableArray c.ToCode())); + var members = new List(); + foreach (var module in Children.OfType()) + { + var typeName = module.Namespace.Substring(0, module.Namespace.Length - 1); + var memberName = MakeName(module.Argument); + members.Add($"public {typeName}? {memberName} {{ get; set; }}"); + } + + return $$""" + using System; + using System.Xml; + using Yang.Attributes; + namespace {{Namespace}}; + /// + ///Configuration root object for {{Namespace}} based on provided .yang modules + ///{{AttributeString}} + public class Configuration + { + {{Indent(string.Join("\n", members))}} + } + """; } } \ No newline at end of file diff --git a/YangParser/SemanticModel/Statement.cs b/YangParser/SemanticModel/Statement.cs index 3b78f78..6a6e630 100644 --- a/YangParser/SemanticModel/Statement.cs +++ b/YangParser/SemanticModel/Statement.cs @@ -135,7 +135,7 @@ public string AttributeString { get { - Attributes.Add("XPath(\"" + XPath + '"' + ')'); + Attributes.Add("XPath(@\"" + XPath + '"' + ')'); return "\n" + string.Join("\n", Attributes.OrderBy(x => x.Length).Select(attr => $"[{attr}]")); } }