示例#1
0
        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);
        }
示例#2
0
 public bool CanHandle(string name, ResourceFileHandlerContext context) => name.EndsWith(".baml", StringComparison.OrdinalIgnoreCase);