hybridclr_unity/Editor/Link/LinkXmlWriter.cs

54 lines
1.9 KiB
C#
Raw Normal View History

2022-09-22 08:56:07 +08:00
using dnlib.DotNet;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace HybridCLR.Editor.Link
2022-09-22 08:56:07 +08:00
{
internal class LinkXmlWriter
{
public void Write(string outputLinkXmlFile, HashSet<TypeRef> refTypes)
{
string parentDir = Directory.GetParent(outputLinkXmlFile).FullName;
Directory.CreateDirectory(parentDir);
var writer = System.Xml.XmlWriter.Create(outputLinkXmlFile,
new System.Xml.XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true});
writer.WriteStartDocument();
writer.WriteStartElement("linker");
var typesByAssembly = refTypes.GroupBy(t => t.DefinitionAssembly.Name.String).ToList();
2023-06-27 08:18:11 +08:00
typesByAssembly.Sort((a, b) => String.Compare(a.Key, b.Key, StringComparison.Ordinal));
2022-09-22 08:56:07 +08:00
foreach(var assembly in typesByAssembly)
{
writer.WriteStartElement("assembly");
writer.WriteAttributeString("fullname", assembly.Key);
2023-06-27 08:18:11 +08:00
List<string> assTypeNames = assembly.Select(t => t.FullName).ToList();
assTypeNames.Sort(string.CompareOrdinal);
foreach(var typeName in assTypeNames)
2022-09-22 08:56:07 +08:00
{
#if UNITY_2023_1_OR_NEWER
if (typeName == "UnityEngine.Debug")
{
continue;
}
#endif
2022-09-22 08:56:07 +08:00
writer.WriteStartElement("type");
2023-06-27 08:18:11 +08:00
writer.WriteAttributeString("fullname", typeName);
2022-09-22 08:56:07 +08:00
writer.WriteAttributeString("preserve", "all");
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
}
}