mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Add type imports to disassembler
This commit is contained in:
@@ -19,17 +19,18 @@ public class Disassembler
|
|||||||
|
|
||||||
public IEnumerable<IImport> GetImports()
|
public IEnumerable<IImport> GetImports()
|
||||||
{
|
{
|
||||||
// Keep track of which namespaces have already been imported,
|
// Keep track of what has already been imported. Skip self and default UIX namespace.
|
||||||
// and skip self and default UIX namespace
|
Dictionary<string, string> importedUris = new() {
|
||||||
HashSet<string> importedUris = [_loadResult.Uri, "http://schemas.microsoft.com/2007/uix"];
|
[_loadResult.Uri] = "me",
|
||||||
|
["http://schemas.microsoft.com/2007/uix"] = null
|
||||||
|
};
|
||||||
|
|
||||||
foreach (var typeImport in _loadResult.ImportTables.TypeImports)
|
foreach (var typeImport in _loadResult.ImportTables.TypeImports)
|
||||||
{
|
{
|
||||||
var uri = typeImport.Owner.Uri;
|
var uri = typeImport.Owner.Uri;
|
||||||
if (importedUris.Contains(uri))
|
if (!importedUris.TryGetValue(uri, out var namespacePrefix))
|
||||||
continue;
|
{
|
||||||
|
namespacePrefix = uri;
|
||||||
string name = uri;
|
|
||||||
var schemeLength = uri.IndexOf("://");
|
var schemeLength = uri.IndexOf("://");
|
||||||
if (schemeLength > 0)
|
if (schemeLength > 0)
|
||||||
{
|
{
|
||||||
@@ -37,7 +38,7 @@ public class Disassembler
|
|||||||
if (scheme == "assembly")
|
if (scheme == "assembly")
|
||||||
{
|
{
|
||||||
// Assume the URI represents a C# namespace
|
// Assume the URI represents a C# namespace
|
||||||
name = uri.Split('.', '/', '\\', '!')[^1];
|
namespacePrefix = uri.Split('.', '/', '\\', '!')[^1];
|
||||||
|
|
||||||
// Remove the extra assembly info
|
// Remove the extra assembly info
|
||||||
uri = uri.Split(',')[0];
|
uri = uri.Split(',')[0];
|
||||||
@@ -46,11 +47,16 @@ public class Disassembler
|
|||||||
{
|
{
|
||||||
// Assume the URI represents a file,
|
// Assume the URI represents a file,
|
||||||
// skip the extension
|
// skip the extension
|
||||||
name = uri.Split('.', '/', '\\', '!')[^2];
|
namespacePrefix = uri.Split('.', '/', '\\', '!')[^2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return new NamespaceImport(uri, name.Camelize());
|
namespacePrefix = namespacePrefix.Camelize();
|
||||||
|
importedUris.Add(uri, namespacePrefix);
|
||||||
|
yield return new NamespaceImport(uri, namespacePrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new TypeImport(namespacePrefix, typeImport.Name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user