public string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, ResourceFileHandlerContext context) { BamlDecompilerTypeSystem typeSystem = new BamlDecompilerTypeSystem(assembly.GetPEFileOrNull(), assembly.GetAssemblyResolver()); var decompiler = new XamlDecompiler(typeSystem, new BamlDecompilerSettings() { ThrowOnAssemblyResolveErrors = context.DecompilationOptions.DecompilerSettings.ThrowOnAssemblyResolveErrors }); decompiler.CancellationToken = context.DecompilationOptions.CancellationToken; var result = decompiler.Decompile(stream); var typeDefinition = result.TypeName.HasValue ? typeSystem.MainModule.GetTypeDefinition(result.TypeName.Value.TopLevelTypeName) : null; if (typeDefinition != null) { fileName = WholeProjectDecompiler.CleanUpPath(typeDefinition.ReflectionName) + ".xaml"; var partialTypeInfo = new PartialTypeInfo(typeDefinition); foreach (var member in result.GeneratedMembers) { partialTypeInfo.AddDeclaredMember(member); } context.AddPartialTypeInfo(partialTypeInfo); } else { fileName = Path.ChangeExtension(fileName, ".xaml"); } string saveFileName = Path.Combine(context.DecompilationOptions.SaveAsProjectDirectory, fileName); Directory.CreateDirectory(Path.GetDirectoryName(saveFileName)); result.Xaml.Save(saveFileName); return(fileName); }
internal static XDocument LoadIntoDocument(PEFile module, IAssemblyResolver assemblyResolver, Stream stream, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var document = BamlReader.ReadDocument(stream, cancellationToken); var xaml = new XamlDecompiler().Decompile(new BamlDecompilerTypeSystem(module, assemblyResolver), document, cancellationToken, new BamlDecompilerOptions(), null); return(xaml); }
void LoadBaml(AvalonEditTextOutput output, CancellationToken cancellationToken) { var asm = this.Ancestors().OfType <AssemblyTreeNode>().First().LoadedAssembly; using var data = OpenStream(); BamlDecompilerTypeSystem typeSystem = new BamlDecompilerTypeSystem(asm.GetPEFileOrNull(), asm.GetAssemblyResolver()); var decompiler = new XamlDecompiler(typeSystem, new BamlDecompilerSettings()); decompiler.CancellationToken = cancellationToken; var result = decompiler.Decompile(data); output.Write(result.Xaml.ToString()); }
public string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, DecompilationOptions options) { BamlDecompilerTypeSystem typeSystem = new BamlDecompilerTypeSystem(assembly.GetPEFileOrNull(), assembly.GetAssemblyResolver()); var decompiler = new XamlDecompiler(typeSystem, new BamlDecompilerSettings() { ThrowOnAssemblyResolveErrors = options.DecompilerSettings.ThrowOnAssemblyResolveErrors }); decompiler.CancellationToken = options.CancellationToken; fileName = Path.ChangeExtension(fileName, ".xaml"); var result = decompiler.Decompile(stream); result.Xaml.Save(Path.Combine(options.SaveAsProjectDirectory, fileName)); return(fileName); }