Browse Source

#2718: Move XAML files that have an x:Class declaration next to their C# counterparts when using WholeProjectDecompiler.

stash/beautify-enum-member-declarations
Siegfried Pammer 3 years ago
parent
commit
9ed4d084d5
  1. 7
      ILSpy.BamlDecompiler/BamlDecompilationResult.cs
  2. 10
      ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs
  3. 1
      ILSpy.BamlDecompiler/Rewrite/XClassRewritePass.cs
  4. 3
      ILSpy.BamlDecompiler/XamlContext.cs
  5. 3
      ILSpy.BamlDecompiler/XamlDecompiler.cs

7
ILSpy.BamlDecompiler/BamlDecompilationResult.cs

@ -20,6 +20,8 @@ using System.Collections.Generic; @@ -20,6 +20,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using ICSharpCode.Decompiler.TypeSystem;
namespace ILSpy.BamlDecompiler
{
public class BamlDecompilationResult
@ -27,9 +29,12 @@ namespace ILSpy.BamlDecompiler @@ -27,9 +29,12 @@ namespace ILSpy.BamlDecompiler
public XDocument Xaml { get; }
public List<string> AssemblyReferences { get; }
public BamlDecompilationResult(XDocument xaml, IEnumerable<string> assemblyReferences)
public FullTypeName? TypeName { get; }
public BamlDecompilationResult(XDocument xaml, FullTypeName? typeName, IEnumerable<string> assemblyReferences)
{
this.Xaml = xaml;
this.TypeName = typeName;
this.AssemblyReferences = assemblyReferences.ToList();
}
}

10
ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.ComponentModel.Composition;
using System.IO;
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TreeNodes;
@ -53,8 +54,15 @@ namespace ILSpy.BamlDecompiler @@ -53,8 +54,15 @@ namespace ILSpy.BamlDecompiler
ThrowOnAssemblyResolveErrors = options.DecompilerSettings.ThrowOnAssemblyResolveErrors
});
decompiler.CancellationToken = options.CancellationToken;
fileName = Path.ChangeExtension(fileName, ".xaml");
var result = decompiler.Decompile(stream);
if (result.TypeName.HasValue)
{
fileName = WholeProjectDecompiler.CleanUpPath(result.TypeName.Value.ReflectionName) + ".xaml";
}
else
{
fileName = Path.ChangeExtension(fileName, ".xaml");
}
result.Xaml.Save(Path.Combine(options.SaveAsProjectDirectory, fileName));
return fileName;
}

1
ILSpy.BamlDecompiler/Rewrite/XClassRewritePass.cs

@ -62,6 +62,7 @@ namespace ILSpy.BamlDecompiler.Rewrite @@ -62,6 +62,7 @@ namespace ILSpy.BamlDecompiler.Rewrite
attrs.Insert(0, new XAttribute(classModifierName, "internal"));
}
attrs.Insert(0, new XAttribute(attrName, type.ResolvedType.FullName));
ctx.XClassNames.Add(type.ResolvedType.FullName);
elem.ReplaceAttributes(attrs);
}
}

3
ILSpy.BamlDecompiler/XamlContext.cs

@ -40,6 +40,7 @@ namespace ILSpy.BamlDecompiler @@ -40,6 +40,7 @@ namespace ILSpy.BamlDecompiler
TypeSystem = typeSystem;
NodeMap = new Dictionary<BamlRecord, BamlBlockNode>();
XmlNs = new XmlnsDictionary();
XClassNames = new List<string>();
}
Dictionary<ushort, XamlType> typeMap = new Dictionary<ushort, XamlType>();
@ -54,6 +55,8 @@ namespace ILSpy.BamlDecompiler @@ -54,6 +55,8 @@ namespace ILSpy.BamlDecompiler
public BamlNode RootNode { get; private set; }
public IDictionary<BamlRecord, BamlBlockNode> NodeMap { get; }
public List<string> XClassNames { get; }
public XmlnsDictionary XmlNs { get; }
public static XamlContext Construct(IDecompilerTypeSystem typeSystem, BamlDocument document, CancellationToken token, BamlDecompilerSettings bamlDecompilerOptions)

3
ILSpy.BamlDecompiler/XamlDecompiler.cs

@ -120,7 +120,8 @@ namespace ILSpy.BamlDecompiler @@ -120,7 +120,8 @@ namespace ILSpy.BamlDecompiler
}
var assemblyReferences = ctx.Baml.AssemblyIdMap.Select(a => a.Value.AssemblyFullName);
return new BamlDecompilationResult(xaml, assemblyReferences);
var typeName = ctx.XClassNames.FirstOrDefault() is string s ? (FullTypeName?)new FullTypeName(s) : null;
return new BamlDecompilationResult(xaml, typeName, assemblyReferences);
}
}
}
Loading…
Cancel
Save