Example #1
0
        public BamlDecompilationResult Decompile(Stream stream)
        {
            var ct       = CancellationToken;
            var document = BamlReader.ReadDocument(stream, ct);
            var ctx      = XamlContext.Construct(typeSystem, document, ct, settings);

            var handler = HandlerMap.LookupHandler(ctx.RootNode.Type);
            var elem    = handler.Translate(ctx, ctx.RootNode, null);

            var xaml = new XDocument();

            xaml.Add(elem.Xaml.Element);

            foreach (var pass in rewritePasses)
            {
                ct.ThrowIfCancellationRequested();
                pass.Run(ctx, xaml);
            }

            var assemblyReferences = ctx.Baml.AssemblyIdMap.Select(a => a.Value.AssemblyFullName);
            var typeName           = ctx.XClassNames.FirstOrDefault() is string s ? (FullTypeName?)new FullTypeName(s) : null;

            return(new BamlDecompilationResult(xaml, typeName, assemblyReferences, ctx.GeneratedMembers));
        }