From b8fd7b4d995f503045a7fddfcc8e9c60d44bb5d9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 21 Jun 2011 18:34:04 +0200 Subject: [PATCH] fixed static resource handling --- .../KeyMapping.cs | 6 +++++ .../XmlBamlReader.cs | 18 ++++++--------- .../Tests/Cases/Dictionary1.xaml | 23 +++++++++++++++++++ .../Tests/ILSpy.BamlDecompiler.Tests.csproj | 1 + ILSpy.BamlDecompiler/Tests/TestRunner.cs | 17 ++++++++++---- 5 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 ILSpy.BamlDecompiler/Tests/Cases/Dictionary1.xaml diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs index 0b20620fc..abda8e317 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs @@ -36,5 +36,11 @@ namespace Ricciolo.StylesExplorer.MarkupReflection this.staticResources = new List(); this.Position = -1; } + + public override string ToString() + { + return '"' + KeyString + '"'; + } + } } diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index 875b1d1cf..4e8a4a693 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -41,9 +41,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection bool intoAttribute = false; bool initialized; bool _eof; - - bool isPartialDefKeysClosed = true; - bool isDefKeysClosed = true; #region Context Stack layer = new Stack(); @@ -994,6 +991,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection bool sharedSet = reader.ReadBoolean(); string text = this.stringTable[stringId]; + Debug.Print("KeyString: " + text); if (text == null) throw new NotSupportedException(); @@ -1425,8 +1423,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection resource = this.stringTable[typeIdentifier]; } - //this.staticResourceTable.Add(resource); - isPartialDefKeysClosed = true; LastKey.StaticResources.Add(resource); } @@ -1508,11 +1504,11 @@ namespace Ricciolo.StylesExplorer.MarkupReflection void ReadPropertyWithStaticResourceIdentifier() { - short identifier = reader.ReadInt16(); - short staticIdentifier = reader.ReadInt16(); + short propertyId = reader.ReadInt16(); + short index = reader.ReadInt16(); - PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); - object staticResource = GetStaticResource(staticIdentifier); + PropertyDeclaration pd = this.GetPropertyDeclaration(propertyId); + object staticResource = GetStaticResource(index); string prefix = this.LookupPrefix(XmlPIMapping.PresentationNamespace, false); string value = String.Format("{{{0}{1}StaticResource {2}}}", prefix, (String.IsNullOrEmpty(prefix)) ? String.Empty : ":", staticResource); @@ -1525,8 +1521,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection object GetStaticResource(short identifier) { - if (identifier < LastKey.StaticResources.Count) - return LastKey.StaticResources[(int)identifier]; + if (identifier < keys[currentKey - 1].StaticResources.Count) + return keys[currentKey - 1].StaticResources[(int)identifier]; // return "???" + identifier +"???"; throw new ArgumentException("Cannot find StaticResource", "identifier"); diff --git a/ILSpy.BamlDecompiler/Tests/Cases/Dictionary1.xaml b/ILSpy.BamlDecompiler/Tests/Cases/Dictionary1.xaml new file mode 100644 index 000000000..594de1dad --- /dev/null +++ b/ILSpy.BamlDecompiler/Tests/Cases/Dictionary1.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj b/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj index b7174e31a..3b1d5c14d 100644 --- a/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj +++ b/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj @@ -128,6 +128,7 @@ + \ No newline at end of file diff --git a/ILSpy.BamlDecompiler/Tests/TestRunner.cs b/ILSpy.BamlDecompiler/Tests/TestRunner.cs index 6469bc081..df671eee4 100644 --- a/ILSpy.BamlDecompiler/Tests/TestRunner.cs +++ b/ILSpy.BamlDecompiler/Tests/TestRunner.cs @@ -61,18 +61,27 @@ namespace ILSpy.BamlDecompiler.Tests RunTest("cases/attachedevent"); } + [Test] + public void Dictionary1() + { + RunTest("cases/dictionary1"); + } + #region RunTest void RunTest(string name) { - string asmPath = typeof(TestRunner).Assembly.Location; + RunTest(name, typeof(TestRunner).Assembly.Location, Path.Combine("..\\..\\Tests", name + ".xaml")); + } + + void RunTest(string name, string asmPath, string sourcePath) + { var assembly = AssemblyDefinition.ReadAssembly(asmPath); Resource res = assembly.MainModule.Resources.First(); Stream bamlStream = LoadBaml(res, name + ".baml"); Assert.IsNotNull(bamlStream); XDocument document = BamlResourceEntryNode.LoadIntoDocument(new DefaultAssemblyResolver(), assembly, bamlStream); - string path = Path.Combine("..\\..\\Tests", name + ".xaml"); - - CodeAssert.AreEqual(File.ReadAllText(path), document.ToString()); + + CodeAssert.AreEqual(File.ReadAllText(sourcePath), document.ToString()); } Stream LoadBaml(Resource res, string name)