From 42613e716668ed07867c82fd406731703e812559 Mon Sep 17 00:00:00 2001 From: Thomas Cashman Date: Sun, 16 Jan 2022 16:49:44 +0000 Subject: [PATCH] Release 1.0.0 --- RdXml.Test/Sample/TestAttribute.cs | 20 ++++ RdXml.Test/Sample/TestClass.cs | 20 ++++ RdXml.Test/TypeTests.cs | 111 +++++++++++++++++- RdXml/RdAssembly.cs | 20 +++- RdXml/RdAttributeImplies.cs | 20 +++- RdXml/RdDirective.cs | 16 +++ RdXml/RdElement.cs | 41 ++++++- RdXml/RdEvent.cs | 2 +- RdXml/RdField.cs | 16 ++- RdXml/RdGenericParameter.cs | 2 +- RdXml/RdMethod.cs | 30 ++++- RdXml/RdNamespace.cs | 30 +++-- RdXml/RdProperty.cs | 16 ++- RdXml/RdSubtypes.cs | 19 ++- RdXml/RdType.cs | 34 ++++++ RdXml/RdTypeInstantiation.cs | 77 +++++++++++- RdXmlConverter.Core/Program.cs | 14 ++- .../RdXmlConverter.Core.csproj | 3 +- RdXmlConverter.Framework/Program.cs | 47 +++++++- .../RdXmlConverter.Framework.csproj | 2 +- 20 files changed, 502 insertions(+), 38 deletions(-) create mode 100644 RdXml.Test/Sample/TestAttribute.cs create mode 100644 RdXml.Test/Sample/TestClass.cs diff --git a/RdXml.Test/Sample/TestAttribute.cs b/RdXml.Test/Sample/TestAttribute.cs new file mode 100644 index 0000000..80e6d22 --- /dev/null +++ b/RdXml.Test/Sample/TestAttribute.cs @@ -0,0 +1,20 @@ +/** + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/ + * + * Copyright 2022 Thomas Cashman + * + * See LICENSE file + */ +using System; +using System.Collections.Generic; +using System.Text; + +namespace RdXml.Test.Sample +{ + [System.AttributeUsage(System.AttributeTargets.Class)] + public class TestAttribute : System.Attribute + { + } +} diff --git a/RdXml.Test/Sample/TestClass.cs b/RdXml.Test/Sample/TestClass.cs new file mode 100644 index 0000000..f17f71e --- /dev/null +++ b/RdXml.Test/Sample/TestClass.cs @@ -0,0 +1,20 @@ +/** + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/ + * + * Copyright 2022 Thomas Cashman + * + * See LICENSE file + */ +using System; +using System.Collections.Generic; +using System.Text; + +namespace RdXml.Test.Sample +{ + [TestAttribute] + public class TestClass + { + } +} diff --git a/RdXml.Test/TypeTests.cs b/RdXml.Test/TypeTests.cs index 9b2e470..5a8f55d 100644 --- a/RdXml.Test/TypeTests.cs +++ b/RdXml.Test/TypeTests.cs @@ -8,8 +8,10 @@ * See LICENSE file */ using Microsoft.VisualStudio.TestTools.UnitTesting; +using RdXml.Test.Sample; using System; using System.Collections.Generic; +using System.IO; using System.Text; using System.Xml; @@ -18,12 +20,22 @@ namespace RdXml.Test [TestClass] public class TypeTests { + private XmlWriterSettings xmlWriterSettings; + + [TestInitialize] + public void TestInit() + { + xmlWriterSettings = new XmlWriterSettings(); + xmlWriterSettings.Indent = true; + xmlWriterSettings.OmitXmlDeclaration = true; + } + [TestMethod] - public void TestSubType() + public void TestSubTypes() { string inputXml = @" - + @@ -35,6 +47,101 @@ public void TestSubType() Assert.IsNotNull(directive.Application); Assert.AreEqual(1, directive.Application.Types.Count); Assert.IsNotNull(directive.Application.Types[0].SubTypes); + + StringWriter result = new StringWriter(); + directive.WriteNativeAOT(XmlWriter.Create(result, xmlWriterSettings)); + + string expectedXml = @" + + + + + + + + + + + + + + + + + +"; + Assert.AreEqual(expectedXml, result.ToString()); + } + + [TestMethod] + public void TestNamespace() + { + string inputXml = @" + + + + "; + + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(inputXml); + RdDirective directive = new RdDirective(xmlDocument); + Assert.IsNotNull(directive.Application); + Assert.AreEqual(1, directive.Application.Namespaces.Count); + + StringWriter result = new StringWriter(); + directive.WriteNativeAOT(XmlWriter.Create(result, xmlWriterSettings)); + + string expectedXml = @" + + + + + + + + + + + + + + + + + +"; + Assert.AreEqual(expectedXml, result.ToString()); + } + + [TestMethod] + public void TestAttributeImplies() + { + Type type = typeof(TestAttribute); + + string inputXml = @" + + + + + + "; + + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(inputXml); + RdDirective directive = new RdDirective(xmlDocument); + Assert.IsNotNull(directive.Application); + Assert.AreEqual(1, directive.Application.Types.Count); + + StringWriter result = new StringWriter(); + directive.WriteNativeAOT(XmlWriter.Create(result, xmlWriterSettings)); + + string expectedXml = @" + + + + +"; + Assert.AreEqual(expectedXml, result.ToString()); } } } diff --git a/RdXml/RdAssembly.cs b/RdXml/RdAssembly.cs index 732958c..88602d2 100644 --- a/RdXml/RdAssembly.cs +++ b/RdXml/RdAssembly.cs @@ -35,13 +35,25 @@ public override void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentEl { xmlElement.SetAttribute(ATTRIBUTE_DYNAMIC, VALUE_REQUIRED_ALL); } - if(HasMarshalDelegateAttribute || HasMarshalStructureAttribute) + if (HasMarshalStructureAttribute) + { + xmlElement.SetAttribute(RdElement.ATTRIBUTE_MARSHAL_STRUCTURE, "Required All"); + } + if (HasMarshalDelegateAttribute || HasMarshalStructureAttribute) { IEnumerable delegates = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(t => t.GetTypes()) - .Where(t => !t.IsClass && t.Assembly.FullName == assemblyName); + .Where(t => typeof(Delegate).IsAssignableFrom(t) && t.Assembly.FullName == assemblyName); foreach (Type type in delegates) { + if (type.IsGenericParameter) + { + continue; + } + if (IsCompilerGenerated(type)) + { + continue; + } if (!writtenTypes.Add(type)) { continue; @@ -52,10 +64,6 @@ public override void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentEl { delegateElement.SetAttribute(RdElement.ATTRIBUTE_MARSHAL_DELEGATE, "Required All"); } - if (HasMarshalStructureAttribute) - { - delegateElement.SetAttribute(RdElement.ATTRIBUTE_MARSHAL_STRUCTURE, "Required All"); - } xmlElement.AppendChild(delegateElement); } } diff --git a/RdXml/RdAttributeImplies.cs b/RdXml/RdAttributeImplies.cs index cd0fdbe..ae81ad3 100644 --- a/RdXml/RdAttributeImplies.cs +++ b/RdXml/RdAttributeImplies.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Text; using System.Xml; +using System.Linq; namespace RdXml { @@ -22,9 +23,24 @@ public RdAttributeImplies(RdElement parent, XmlElement xmlElement) : base(parent { } - public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) + public override void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes) { - throw new NotImplementedException(); + RdType parentTypeElement = (RdType)Parent; + string typeName = parentTypeElement.TypeName; + Type resolvedType = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => t.FullName == typeName).First(); + + IEnumerable typesWithAttribute = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => t.GetCustomAttributes(resolvedType, true).Length > 0); + foreach (Type type in typesWithAttribute) + { + AppendType(xmlDocument, parentElement, writtenTypes, type, + HasReflectAttribute, + HasMarshalDelegateAttribute, + HasMarshalStructureAttribute); + } } } } diff --git a/RdXml/RdDirective.cs b/RdXml/RdDirective.cs index 0a3ac12..15da24a 100644 --- a/RdXml/RdDirective.cs +++ b/RdXml/RdDirective.cs @@ -47,6 +47,22 @@ public void WriteNativeAOT(Stream outputStream) result.Save(outputStream); } + public void WriteNativeAOT(TextWriter textWriter) + { + XmlDocument result = new XmlDocument(); + HashSet writtenTypes = new HashSet(); + WriteNativeAOT(result, result.DocumentElement, writtenTypes); + result.Save(textWriter); + } + + public void WriteNativeAOT(XmlWriter xmlWriter) + { + XmlDocument result = new XmlDocument(); + HashSet writtenTypes = new HashSet(); + WriteNativeAOT(result, result.DocumentElement, writtenTypes); + result.Save(xmlWriter); + } + public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) { XmlElement rootElement = result.CreateElement(ELEMENT_TAG); diff --git a/RdXml/RdElement.cs b/RdXml/RdElement.cs index c9f6af8..880e3db 100644 --- a/RdXml/RdElement.cs +++ b/RdXml/RdElement.cs @@ -9,6 +9,7 @@ */ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Text; using System.Xml; @@ -38,7 +39,45 @@ public RdElement(RdElement parent, XmlElement xmlElement) XmlElement = xmlElement; } - public abstract void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes); + public abstract void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes); + + protected void AppendType(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes, + Type type, bool dynamic, bool marshalDelegate, bool marshalStructure) + { + if(type.IsGenericParameter) + { + return; + } + if(IsCompilerGenerated(type)) + { + return; + } + if(!writtenTypes.Add(type)) + { + return; + } + XmlElement xmlElement = xmlDocument.CreateElement(RdType.ELEMENT_TAG); + xmlElement.SetAttribute(ATTRIBUTE_NAME, type.FullName); + parentElement.AppendChild(xmlElement); + + if(dynamic) + { + xmlElement.SetAttribute(ATTRIBUTE_DYNAMIC, VALUE_REQUIRED_ALL); + } + if(marshalDelegate) + { + xmlElement.SetAttribute(ATTRIBUTE_MARSHAL_DELEGATE, VALUE_REQUIRED_ALL); + } + if(marshalStructure) + { + xmlElement.SetAttribute(ATTRIBUTE_MARSHAL_STRUCTURE, VALUE_REQUIRED_ALL); + } + } + + protected bool IsCompilerGenerated(Type type) + { + return Attribute.GetCustomAttribute(type, typeof(CompilerGeneratedAttribute)) != null; + } public bool HasReflectAttribute { diff --git a/RdXml/RdEvent.cs b/RdXml/RdEvent.cs index d9eb2fc..e44f5df 100644 --- a/RdXml/RdEvent.cs +++ b/RdXml/RdEvent.cs @@ -24,7 +24,7 @@ public RdEvent(RdElement parent, XmlElement xmlElement) : base(parent, xmlElemen public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) { - throw new NotImplementedException(); + //TODO: How to handle this? } } } diff --git a/RdXml/RdField.cs b/RdXml/RdField.cs index d7c2bda..c431d83 100644 --- a/RdXml/RdField.cs +++ b/RdXml/RdField.cs @@ -9,8 +9,10 @@ */ using System; using System.Collections.Generic; +using System.Reflection; using System.Text; using System.Xml; +using System.Linq; namespace RdXml { @@ -24,7 +26,19 @@ public RdField(RdElement parent, XmlElement xmlElement) : base(parent, xmlElemen public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) { - throw new NotImplementedException(); + RdType parentTypeElement = (RdType)Parent; + string typeName = parentTypeElement.TypeName; + Type parentType = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => t.FullName == typeName).First(); + AppendType(result, parentElement, writtenTypes, parentType, true, false, false); + + FieldInfo fieldInfo = parentType.GetField(XmlElement.GetAttribute(ATTRIBUTE_NAME)); + if (fieldInfo == null) + { + return; + } + AppendType(result, parentElement, writtenTypes, fieldInfo.FieldType, true, false, false); } } } diff --git a/RdXml/RdGenericParameter.cs b/RdXml/RdGenericParameter.cs index 1ce535d..aed60bf 100644 --- a/RdXml/RdGenericParameter.cs +++ b/RdXml/RdGenericParameter.cs @@ -24,7 +24,7 @@ public RdGenericParameter(RdElement parent, XmlElement xmlElement) : base(parent public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) { - throw new NotImplementedException(); + //TODO: How to resolve this? Scan everything? } } } diff --git a/RdXml/RdMethod.cs b/RdXml/RdMethod.cs index 606b643..b2e5edc 100644 --- a/RdXml/RdMethod.cs +++ b/RdXml/RdMethod.cs @@ -9,8 +9,10 @@ */ using System; using System.Collections.Generic; +using System.Reflection; using System.Text; using System.Xml; +using System.Linq; namespace RdXml { @@ -24,7 +26,33 @@ public RdMethod(RdElement parent, XmlElement xmlElement) : base(parent, xmlEleme public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) { - throw new NotImplementedException(); + RdType parentTypeElement = (RdType)Parent; + string typeName = parentTypeElement.TypeName; + Type parentType = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => t.FullName == typeName).First(); + AppendType(result, parentElement, writtenTypes, parentType, true, false, false); + + foreach(MethodInfo methodInfo in parentType.GetMethods()) + { + if(!methodInfo.Name.Equals(XmlElement.GetAttribute(ATTRIBUTE_NAME))) + { + continue; + } + if(methodInfo.ReturnType != null) + { + AppendType(result, parentElement, writtenTypes, methodInfo.ReturnType, true, false, false); + } + ParameterInfo[] parameters = methodInfo.GetParameters(); + if(parameters == null) + { + continue; + } + foreach(ParameterInfo parameter in parameters) + { + AppendType(result, parentElement, writtenTypes, parameter.ParameterType, true, false, false); + } + } } } } diff --git a/RdXml/RdNamespace.cs b/RdXml/RdNamespace.cs index 7a68ce4..7187d99 100644 --- a/RdXml/RdNamespace.cs +++ b/RdXml/RdNamespace.cs @@ -72,17 +72,25 @@ private void WriteNativeAOTTypes(XmlDocument xmlDocument, XmlElement parentEleme { classes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(t => t.GetTypes()) - .Where(t => t.IsClass && t.Namespace == namespaceName && t.Assembly.FullName == assemblyName); + .Where(t => !typeof(Delegate).IsAssignableFrom(t) && t.Namespace == namespaceName && t.Assembly.FullName == assemblyName); } else { classes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(t => t.GetTypes()) - .Where(t => t.IsClass && t.Namespace == namespaceName); + .Where(t => !typeof(Delegate).IsAssignableFrom(t) && t.Namespace == namespaceName); } foreach (Type type in classes) { + if (type.IsGenericParameter) + { + continue; + } + if (IsCompilerGenerated(type)) + { + continue; + } if (!writtenTypes.Add(type)) { continue; @@ -93,6 +101,10 @@ private void WriteNativeAOTTypes(XmlDocument xmlDocument, XmlElement parentEleme { typeElement.SetAttribute(RdElement.ATTRIBUTE_DYNAMIC, VALUE_REQUIRED_ALL); } + if (HasMarshalStructureAttribute) + { + typeElement.SetAttribute(RdElement.ATTRIBUTE_MARSHAL_STRUCTURE, VALUE_REQUIRED_ALL); + } parentElement.AppendChild(typeElement); } } @@ -101,9 +113,17 @@ private void WriteNativeAOTDelegates(XmlDocument xmlDocument, XmlElement parentE { IEnumerable delegates = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(t => t.GetTypes()) - .Where(t => !t.IsClass && t.Namespace == namespaceName); + .Where(t => typeof(Delegate).IsAssignableFrom(t) && t.Namespace == namespaceName); foreach (Type type in delegates) { + if (type.IsGenericParameter) + { + continue; + } + if (IsCompilerGenerated(type)) + { + continue; + } if (!writtenTypes.Add(type)) { continue; @@ -114,10 +134,6 @@ private void WriteNativeAOTDelegates(XmlDocument xmlDocument, XmlElement parentE { delegateElement.SetAttribute(RdElement.ATTRIBUTE_MARSHAL_DELEGATE, VALUE_REQUIRED_ALL); } - if (HasMarshalStructureAttribute) - { - delegateElement.SetAttribute(RdElement.ATTRIBUTE_MARSHAL_STRUCTURE, VALUE_REQUIRED_ALL); - } parentElement.AppendChild(delegateElement); } } diff --git a/RdXml/RdProperty.cs b/RdXml/RdProperty.cs index 3e6b981..dc2a978 100644 --- a/RdXml/RdProperty.cs +++ b/RdXml/RdProperty.cs @@ -9,8 +9,10 @@ */ using System; using System.Collections.Generic; +using System.Reflection; using System.Text; using System.Xml; +using System.Linq; namespace RdXml { @@ -24,7 +26,19 @@ public RdProperty(RdElement parent, XmlElement xmlElement) : base(parent, xmlEle public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) { - throw new NotImplementedException(); + RdType parentTypeElement = (RdType)Parent; + string typeName = parentTypeElement.TypeName; + Type parentType = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => t.FullName == typeName).First(); + AppendType(result, parentElement, writtenTypes, parentType, true, false, false); + + PropertyInfo propertyInfo = parentType.GetProperty(XmlElement.GetAttribute(ATTRIBUTE_NAME)); + if(propertyInfo == null) + { + return; + } + AppendType(result, parentElement, writtenTypes, propertyInfo.PropertyType, true, false, false); } } } diff --git a/RdXml/RdSubtypes.cs b/RdXml/RdSubtypes.cs index b4dc92b..e2829db 100644 --- a/RdXml/RdSubtypes.cs +++ b/RdXml/RdSubtypes.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Text; using System.Xml; +using System.Linq; namespace RdXml { @@ -22,9 +23,23 @@ public RdSubtypes(RdElement parent, XmlElement xmlElement) : base(parent, xmlEle { } - public override void WriteNativeAOT(XmlDocument result, XmlElement parentElement, HashSet writtenTypes) + public override void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes) { - throw new NotImplementedException(); + RdType parentTypeElement = (RdType)Parent; + string typeName = parentTypeElement.TypeName; + Type resolvedType = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => t.FullName == typeName).First(); + IEnumerable subtypes = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => resolvedType.IsAssignableFrom(t)); + foreach (Type subtype in subtypes) + { + AppendType(xmlDocument, parentElement, writtenTypes, subtype, + HasReflectAttribute, + HasMarshalDelegateAttribute, + HasMarshalStructureAttribute); + } } } } diff --git a/RdXml/RdType.cs b/RdXml/RdType.cs index 50abb6f..24ee874 100644 --- a/RdXml/RdType.cs +++ b/RdXml/RdType.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Text; using System.Xml; +using System.Linq; namespace RdXml { @@ -46,6 +47,39 @@ public RdType(RdElement parent, XmlElement xmlElement) : base(parent, xmlElement public override void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes) { base.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + WriteNativeAOTSubTypes(xmlDocument, parentElement, writtenTypes); + WriteNativeAOTAttributeImplies(xmlDocument, parentElement, writtenTypes); + WriteNativeAOTGenericParameters(xmlDocument, parentElement, writtenTypes); + } + + public void WriteNativeAOTSubTypes(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes) + { + if(SubTypes == null) + { + return; + } + SubTypes.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + + public void WriteNativeAOTAttributeImplies(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes) + { + if(AttributeImplies == null) + { + return; + } + AttributeImplies.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + + public void WriteNativeAOTGenericParameters(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes) + { + foreach(RdGenericParameter genericParameter in GenericParameters) + { + if(genericParameter == null) + { + continue; + } + genericParameter.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } } } } diff --git a/RdXml/RdTypeInstantiation.cs b/RdXml/RdTypeInstantiation.cs index 502fb79..c38cb42 100644 --- a/RdXml/RdTypeInstantiation.cs +++ b/RdXml/RdTypeInstantiation.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Text; using System.Xml; +using System.Linq; namespace RdXml { @@ -74,12 +75,27 @@ public RdTypeInstantiation(RdElement parent, XmlElement xmlElement) : base(paren public override void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentElement, HashSet writtenTypes) { string typeName = TypeName; - Type resolvedType = Type.GetType(typeName); + Type resolvedType = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(t => t.GetTypes()) + .Where(t => t.FullName == typeName).First(); if (writtenTypes.Add(resolvedType)) { - XmlElement xmlElement = xmlDocument.CreateElement(ELEMENT_TAG); - xmlElement.SetAttribute(ATTRIBUTE_NAME, TypeName); - xmlDocument.AppendChild(xmlElement); + XmlElement xmlElement; + + if(!(this is RdType)) + { + //TypeInstantiation has additional Arguments field + //TODO: Implement Arguments field support + xmlElement = xmlDocument.CreateElement(XmlElement.LocalName); + xmlElement.SetAttribute(ATTRIBUTE_NAME, TypeName); + parentElement.AppendChild(xmlElement); + } + else + { + xmlElement = xmlDocument.CreateElement(XmlElement.LocalName); + xmlElement.SetAttribute(ATTRIBUTE_NAME, TypeName); + parentElement.AppendChild(xmlElement); + } if (HasReflectAttribute) { @@ -94,6 +110,35 @@ public override void WriteNativeAOT(XmlDocument xmlDocument, XmlElement parentEl xmlElement.SetAttribute(RdElement.ATTRIBUTE_MARSHAL_STRUCTURE, VALUE_REQUIRED_ALL); } } + + foreach (RdType type in Types) + { + type.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + foreach (RdTypeInstantiation typeInstantiation in TypeInstantiations) + { + typeInstantiation.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + foreach (RdMethod method in Methods) + { + method.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + foreach (RdMethodInstantiation methodInstantiation in MethodInstantiations) + { + methodInstantiation.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + foreach (RdProperty property in Properties) + { + property.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + foreach (RdField field in Fields) + { + field.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } + foreach (RdEvent @event in Events) + { + @event.WriteNativeAOT(xmlDocument, parentElement, writtenTypes); + } } public string TypeName @@ -114,6 +159,30 @@ public string TypeName } } } + else if (Parent is RdType type) + { + string parentTypeName = type.TypeName; + if (!thisName.StartsWith(parentTypeName)) + { + result.Append(parentTypeName); + if (!parentTypeName.EndsWith(".")) + { + result.Append('.'); + } + } + } + else if (Parent is RdTypeInstantiation typeInstantiation) + { + string parentTypeName = typeInstantiation.TypeName; + if (!thisName.StartsWith(parentTypeName)) + { + result.Append(parentTypeName); + if (!parentTypeName.EndsWith(".")) + { + result.Append('.'); + } + } + } result.Append(thisName); return result.ToString(); } diff --git a/RdXmlConverter.Core/Program.cs b/RdXmlConverter.Core/Program.cs index 495f9e0..178289e 100644 --- a/RdXmlConverter.Core/Program.cs +++ b/RdXmlConverter.Core/Program.cs @@ -8,6 +8,7 @@ * See LICENSE file */ using CommandLine; +using RdXml; using System; using System.IO; using System.Reflection; @@ -45,11 +46,18 @@ static void Run(CliOptions options) Assembly.LoadFrom(dllFilename); } - XmlDocument doc = new XmlDocument(); - doc.PreserveWhitespace = true; - doc.Load(options.InputRdXml); + XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); + xmlWriterSettings.Indent = true; + xmlWriterSettings.OmitXmlDeclaration = true; + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.PreserveWhitespace = true; + xmlDocument.Load(options.InputRdXml); + RdDirective directive = new RdDirective(xmlDocument); + StringWriter result = new StringWriter(); + directive.WriteNativeAOT(XmlWriter.Create(result, xmlWriterSettings)); + File.WriteAllText(options.OutputRdXml, result.ToString()); } } } diff --git a/RdXmlConverter.Core/RdXmlConverter.Core.csproj b/RdXmlConverter.Core/RdXmlConverter.Core.csproj index 41e7dad..4b0afc5 100644 --- a/RdXmlConverter.Core/RdXmlConverter.Core.csproj +++ b/RdXmlConverter.Core/RdXmlConverter.Core.csproj @@ -2,7 +2,8 @@ Exe - netcoreapp3.1 + net5.0 + RdXmlConverter diff --git a/RdXmlConverter.Framework/Program.cs b/RdXmlConverter.Framework/Program.cs index cfed55f..936dc62 100644 --- a/RdXmlConverter.Framework/Program.cs +++ b/RdXmlConverter.Framework/Program.cs @@ -7,11 +7,12 @@ * * See LICENSE file */ +using CommandLine; +using RdXml; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; +using System.Reflection; +using System.Xml; namespace RdXmlConverter.Framework { @@ -19,6 +20,44 @@ class Program { static void Main(string[] args) { + Parser.Default.ParseArguments(args) + .WithParsed(options => + { + if (!Directory.Exists(options.InputDllDirectory)) + { + Console.Error.WriteLine(options.InputDllDirectory + " is not a directory"); + return; + } + + Run(options); + }); + } + + static void Run(CliOptions options) + { + string[] dlls = Directory.GetFiles(options.InputDllDirectory, "*.dll"); + if (dlls.Length == 0) + { + Console.Error.WriteLine("No DLLs in specified directory"); + return; + } + foreach (string dllFilename in dlls) + { + Assembly.LoadFrom(dllFilename); + } + + XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); + xmlWriterSettings.Indent = true; + xmlWriterSettings.OmitXmlDeclaration = true; + + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.PreserveWhitespace = true; + xmlDocument.Load(options.InputRdXml); + + RdDirective directive = new RdDirective(xmlDocument); + StringWriter result = new StringWriter(); + directive.WriteNativeAOT(XmlWriter.Create(result, xmlWriterSettings)); + File.WriteAllText(options.OutputRdXml, result.ToString()); } } } diff --git a/RdXmlConverter.Framework/RdXmlConverter.Framework.csproj b/RdXmlConverter.Framework/RdXmlConverter.Framework.csproj index 88e7e2e..cf1bc8d 100644 --- a/RdXmlConverter.Framework/RdXmlConverter.Framework.csproj +++ b/RdXmlConverter.Framework/RdXmlConverter.Framework.csproj @@ -7,7 +7,7 @@ {B4722DD2-7267-4C70-826C-1DABA067797A} Exe RdXmlConverter.Framework - RdXmlConverter.Framework + RdXmlConverter v4.7.2 512 true