Browse Source

fixed static resource handling

pull/252/head
Siegfried Pammer 15 years ago
parent
commit
b8fd7b4d99
  1. 6
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs
  2. 18
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
  3. 23
      ILSpy.BamlDecompiler/Tests/Cases/Dictionary1.xaml
  4. 1
      ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj
  5. 17
      ILSpy.BamlDecompiler/Tests/TestRunner.cs

6
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs

@ -36,5 +36,11 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
this.staticResources = new List<object>(); this.staticResources = new List<object>();
this.Position = -1; this.Position = -1;
} }
public override string ToString()
{
return '"' + KeyString + '"';
}
} }
} }

18
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

@ -41,9 +41,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
bool intoAttribute = false; bool intoAttribute = false;
bool initialized; bool initialized;
bool _eof; bool _eof;
bool isPartialDefKeysClosed = true;
bool isDefKeysClosed = true;
#region Context #region Context
Stack<ReaderContext> layer = new Stack<ReaderContext>(); Stack<ReaderContext> layer = new Stack<ReaderContext>();
@ -994,6 +991,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
bool sharedSet = reader.ReadBoolean(); bool sharedSet = reader.ReadBoolean();
string text = this.stringTable[stringId]; string text = this.stringTable[stringId];
Debug.Print("KeyString: " + text);
if (text == null) if (text == null)
throw new NotSupportedException(); throw new NotSupportedException();
@ -1425,8 +1423,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
resource = this.stringTable[typeIdentifier]; resource = this.stringTable[typeIdentifier];
} }
//this.staticResourceTable.Add(resource);
isPartialDefKeysClosed = true;
LastKey.StaticResources.Add(resource); LastKey.StaticResources.Add(resource);
} }
@ -1508,11 +1504,11 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
void ReadPropertyWithStaticResourceIdentifier() void ReadPropertyWithStaticResourceIdentifier()
{ {
short identifier = reader.ReadInt16(); short propertyId = reader.ReadInt16();
short staticIdentifier = reader.ReadInt16(); short index = reader.ReadInt16();
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = this.GetPropertyDeclaration(propertyId);
object staticResource = GetStaticResource(staticIdentifier); object staticResource = GetStaticResource(index);
string prefix = this.LookupPrefix(XmlPIMapping.PresentationNamespace, false); string prefix = this.LookupPrefix(XmlPIMapping.PresentationNamespace, false);
string value = String.Format("{{{0}{1}StaticResource {2}}}", prefix, (String.IsNullOrEmpty(prefix)) ? String.Empty : ":", staticResource); 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) object GetStaticResource(short identifier)
{ {
if (identifier < LastKey.StaticResources.Count) if (identifier < keys[currentKey - 1].StaticResources.Count)
return LastKey.StaticResources[(int)identifier]; return keys[currentKey - 1].StaticResources[(int)identifier];
// return "???" + identifier +"???"; // return "???" + identifier +"???";
throw new ArgumentException("Cannot find StaticResource", "identifier"); throw new ArgumentException("Cannot find StaticResource", "identifier");

23
ILSpy.BamlDecompiler/Tests/Cases/Dictionary1.xaml

@ -0,0 +1,23 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="VeryDark" A="255" R="70" G="70" B="70" />
<Color x:Key="Dark" A="255" R="102" G="102" B="102" />
<Color x:Key="Medium" A="255" R="140" G="140" B="140" />
<Color x:Key="Light" A="255" R="204" G="204" B="204" />
<Color x:Key="VeryLight" A="255" R="241" G="241" B="241" />
<Color x:Key="OffWhite" A="255" R="255" G="255" B="255" />
<Color x:Key="Highlight" A="255" R="220" G="107" B="47" />
<SolidColorBrush x:Key="VeryDarkBrush" Color="{StaticResource VeryDark}" />
<SolidColorBrush x:Key="DarkBrush" Color="{StaticResource Dark}" />
<SolidColorBrush x:Key="MediumBrush" Color="{StaticResource Medium}" />
<SolidColorBrush x:Key="LightBrush" Color="{StaticResource Light}" />
<SolidColorBrush x:Key="VeryLightBrush" Color="{StaticResource VeryLight}" />
<SolidColorBrush x:Key="OffWhiteBrush" Color="{StaticResource OffWhite}" />
<SolidColorBrush x:Key="HighlightBrush" Color="{StaticResource Highlight}" />
<LinearGradientBrush x:Key="EdgeBorder" StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#0000" Offset="0" />
<GradientStop Color="#1000" Offset="0.65" />
<GradientStop Color="#3000" Offset="1" />
</LinearGradientBrush>
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#6FFF" />
<SolidColorBrush x:Key="SelectedBackgroundBrush" Color="{StaticResource Light}" />
</ResourceDictionary>

1
ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj

@ -128,6 +128,7 @@
</Page> </Page>
<Page Include="Cases\SimpleDictionary.xaml" /> <Page Include="Cases\SimpleDictionary.xaml" />
<Page Include="Cases\SimpleNames.xaml" /> <Page Include="Cases\SimpleNames.xaml" />
<Page Include="Cases\Dictionary1.xaml" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project> </Project>

17
ILSpy.BamlDecompiler/Tests/TestRunner.cs

@ -61,18 +61,27 @@ namespace ILSpy.BamlDecompiler.Tests
RunTest("cases/attachedevent"); RunTest("cases/attachedevent");
} }
[Test]
public void Dictionary1()
{
RunTest("cases/dictionary1");
}
#region RunTest #region RunTest
void RunTest(string name) 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); var assembly = AssemblyDefinition.ReadAssembly(asmPath);
Resource res = assembly.MainModule.Resources.First(); Resource res = assembly.MainModule.Resources.First();
Stream bamlStream = LoadBaml(res, name + ".baml"); Stream bamlStream = LoadBaml(res, name + ".baml");
Assert.IsNotNull(bamlStream); Assert.IsNotNull(bamlStream);
XDocument document = BamlResourceEntryNode.LoadIntoDocument(new DefaultAssemblyResolver(), assembly, bamlStream); XDocument document = BamlResourceEntryNode.LoadIntoDocument(new DefaultAssemblyResolver(), assembly, bamlStream);
string path = Path.Combine("..\\..\\Tests", name + ".xaml");
CodeAssert.AreEqual(File.ReadAllText(sourcePath), document.ToString());
CodeAssert.AreEqual(File.ReadAllText(path), document.ToString());
} }
Stream LoadBaml(Resource res, string name) Stream LoadBaml(Resource res, string name)

Loading…
Cancel
Save