Browse Source

fixed InvalidCastException when trying to read optimized static resource

pull/252/head
Siegfried Pammer 15 years ago
parent
commit
c572835c9e
  1. 36
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

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

@ -334,7 +334,11 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
else else
currentType = (BamlRecordType)type; currentType = (BamlRecordType)type;
if (currentType.ToString().EndsWith("End"))
Debug.Unindent();
Debug.WriteLine(string.Format("{0} (0x{0:x})", currentType)); Debug.WriteLine(string.Format("{0} (0x{0:x})", currentType));
if (currentType.ToString().EndsWith("Start"))
Debug.Indent();
} }
bool SetNextNode() bool SetNextNode()
@ -684,13 +688,10 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
object GetResourceName(short identifier) object GetResourceName(short identifier)
{ {
if (identifier >= 0) if (identifier >= 0) {
{
PropertyDeclaration declaration = this.propertyTable[identifier]; PropertyDeclaration declaration = this.propertyTable[identifier];
return declaration; return declaration;
} } else {
else
{
identifier = (short)-identifier; identifier = (short)-identifier;
bool isNotKey = (identifier > 0xe8); bool isNotKey = (identifier > 0xe8);
if (isNotKey) if (isNotKey)
@ -1404,27 +1405,28 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
void ReadOptimizedStaticResource() void ReadOptimizedStaticResource()
{ {
byte num = reader.ReadByte(); byte flags = reader.ReadByte();
short typeIdentifier = reader.ReadInt16(); short typeIdentifier = reader.ReadInt16();
bool isValueType = (num & 1) == 1; bool isValueType = (flags & 1) == 1;
bool isStaticType = (num & 2) == 2; bool isStaticType = (flags & 2) == 2;
object resource; object resource;
if (isValueType) if (isValueType)
resource = this.GetTypeExtension(typeIdentifier); resource = GetTypeExtension(typeIdentifier);
else if (isStaticType) else if (isStaticType) {
{ object name = GetResourceName(typeIdentifier);
ResourceName resourceName = (ResourceName)this.GetResourceName(typeIdentifier); if (name is ResourceName)
resource = GetStaticExtension(resourceName.Name); resource = GetStaticExtension(((ResourceName)name).Name);
} else if (name is PropertyDeclaration)
else resource = GetStaticExtension(FormatPropertyDeclaration(((PropertyDeclaration)name), true, false, false));
{ else
throw new InvalidOperationException("Invalid resource: " + name.GetType());
} else {
resource = this.stringTable[typeIdentifier]; resource = this.stringTable[typeIdentifier];
} }
//this.staticResourceTable.Add(resource); //this.staticResourceTable.Add(resource);
isPartialDefKeysClosed = true; isPartialDefKeysClosed = true;
// Aggiungo la risorsa nell'ultimo gruppo
LastKey.StaticResources.Add(resource); LastKey.StaticResources.Add(resource);
} }

Loading…
Cancel
Save