Browse Source

Implement PropertyArrayStart/PropertyArrayEnd in BamlDecompiler

pull/728/merge
Siegfried Pammer 9 years ago
parent
commit
d36550c0ac
  1. 1
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlProperty.cs
  2. 214
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

1
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlProperty.cs

@ -48,6 +48,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
Key, Key,
Value, Value,
Content, Content,
Array,
List, List,
Dictionary, Dictionary,
Complex Complex

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

@ -52,12 +52,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public ReaderContext() public ReaderContext()
{ {
this.Previous = this; Previous = this;
} }
public ReaderContext(ReaderContext previous) public ReaderContext(ReaderContext previous)
{ {
this.Previous = previous; Previous = previous;
} }
} }
@ -109,7 +109,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
_resolver = resolver; _resolver = resolver;
reader = new BamlBinaryReader(stream); reader = new BamlBinaryReader(stream);
XamlTypeDeclaration = new TypeDeclaration(this.Resolver, "", "System.Windows.Markup", 0); XamlTypeDeclaration = new TypeDeclaration(Resolver, "", "System.Windows.Markup", 0);
KnownInfo = new KnownInfo(resolver); KnownInfo = new KnownInfo(resolver);
} }
@ -250,13 +250,13 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if ((_currentNode is XmlBamlProperty)) continue; if ((_currentNode is XmlBamlProperty)) continue;
if ((_currentNode is XmlBamlSimpleProperty)) continue; if ((_currentNode is XmlBamlSimpleProperty)) continue;
if (this.NodeType == XmlNodeType.EndElement) if (NodeType == XmlNodeType.EndElement)
{ {
if (readingElements.Count == 1) if (readingElements.Count == 1)
_rootNamespaces = ((IXmlNamespaceResolver)this).GetNamespacesInScope(XmlNamespaceScope.All); _rootNamespaces = ((IXmlNamespaceResolver)this).GetNamespacesInScope(XmlNamespaceScope.All);
readingElements.Pop(); readingElements.Pop();
} }
else if (this.NodeType == XmlNodeType.Element) else if (NodeType == XmlNodeType.Element)
readingElements.Push((XmlBamlElement)_currentNode); readingElements.Push((XmlBamlElement)_currentNode);
return true; return true;
@ -275,16 +275,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
case BamlRecordType.DocumentEnd: case BamlRecordType.DocumentEnd:
break; break;
case BamlRecordType.ElementStart: case BamlRecordType.ElementStart:
this.ReadElementStart(); ReadElementStart();
break; break;
case BamlRecordType.ElementEnd: case BamlRecordType.ElementEnd:
this.ReadElementEnd(); ReadElementEnd();
break; break;
case BamlRecordType.AssemblyInfo: case BamlRecordType.AssemblyInfo:
this.ReadAssemblyInfo(); ReadAssemblyInfo();
break; break;
case BamlRecordType.StringInfo: case BamlRecordType.StringInfo:
this.ReadStringInfo(); ReadStringInfo();
break; break;
case BamlRecordType.LineNumberAndPosition: case BamlRecordType.LineNumberAndPosition:
reader.ReadInt32(); reader.ReadInt32();
@ -294,10 +294,10 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
reader.ReadInt32(); reader.ReadInt32();
break; break;
case BamlRecordType.XmlnsProperty: case BamlRecordType.XmlnsProperty:
this.ReadXmlnsProperty(); ReadXmlnsProperty();
break; break;
case BamlRecordType.ConnectionId: case BamlRecordType.ConnectionId:
this.ReadConnectionId(); ReadConnectionId();
break; break;
case BamlRecordType.DeferableContentStart: case BamlRecordType.DeferableContentStart:
Current.IsDeferred = true; Current.IsDeferred = true;
@ -306,55 +306,55 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
reader.ReadInt32(); reader.ReadInt32();
break; break;
case BamlRecordType.DefAttribute: case BamlRecordType.DefAttribute:
this.ReadDefAttribute(); ReadDefAttribute();
break; break;
case BamlRecordType.DefAttributeKeyType: case BamlRecordType.DefAttributeKeyType:
this.ReadDefAttributeKeyType(); ReadDefAttributeKeyType();
break; break;
case BamlRecordType.DefAttributeKeyString: case BamlRecordType.DefAttributeKeyString:
this.ReadDefAttributeKeyString(); ReadDefAttributeKeyString();
break; break;
case BamlRecordType.AttributeInfo: case BamlRecordType.AttributeInfo:
this.ReadAttributeInfo(); ReadAttributeInfo();
break; break;
case BamlRecordType.PropertyListStart: case BamlRecordType.PropertyListStart:
this.ReadPropertyListStart(); ReadPropertyListStart();
break; break;
case BamlRecordType.PropertyListEnd: case BamlRecordType.PropertyListEnd:
this.ReadPropertyListEnd(); ReadPropertyListEnd();
break; break;
case BamlRecordType.Property: case BamlRecordType.Property:
this.ReadProperty(); ReadProperty();
break; break;
case BamlRecordType.PropertyWithConverter: case BamlRecordType.PropertyWithConverter:
this.ReadPropertyWithConverter(); ReadPropertyWithConverter();
break; break;
case BamlRecordType.PropertyWithExtension: case BamlRecordType.PropertyWithExtension:
this.ReadPropertyWithExtension(); ReadPropertyWithExtension();
break; break;
case BamlRecordType.PropertyDictionaryStart: case BamlRecordType.PropertyDictionaryStart:
this.ReadPropertyDictionaryStart(); ReadPropertyDictionaryStart();
break; break;
case BamlRecordType.PropertyCustom: case BamlRecordType.PropertyCustom:
this.ReadPropertyCustom(); ReadPropertyCustom();
break; break;
case BamlRecordType.PropertyDictionaryEnd: case BamlRecordType.PropertyDictionaryEnd:
this.ReadPropertyDictionaryEnd(); ReadPropertyDictionaryEnd();
break; break;
case BamlRecordType.PropertyComplexStart: case BamlRecordType.PropertyComplexStart:
this.ReadPropertyComplexStart(); ReadPropertyComplexStart();
break; break;
case BamlRecordType.PropertyComplexEnd: case BamlRecordType.PropertyComplexEnd:
this.ReadPropertyComplexEnd(); ReadPropertyComplexEnd();
break; break;
case BamlRecordType.PIMapping: case BamlRecordType.PIMapping:
this.ReadPIMapping(); ReadPIMapping();
break; break;
case BamlRecordType.TypeInfo: case BamlRecordType.TypeInfo:
this.ReadTypeInfo(); ReadTypeInfo();
break; break;
case BamlRecordType.ContentProperty: case BamlRecordType.ContentProperty:
this.ReadContentProperty(); ReadContentProperty();
break; break;
case BamlRecordType.ConstructorParametersStart: case BamlRecordType.ConstructorParametersStart:
ReadConstructorParametersStart(); ReadConstructorParametersStart();
@ -363,31 +363,31 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
ReadConstructorParametersEnd(); ReadConstructorParametersEnd();
break; break;
case BamlRecordType.ConstructorParameterType: case BamlRecordType.ConstructorParameterType:
this.ReadConstructorParameterType(); ReadConstructorParameterType();
break; break;
case BamlRecordType.Text: case BamlRecordType.Text:
this.ReadText(); ReadText();
break; break;
case BamlRecordType.TextWithConverter: case BamlRecordType.TextWithConverter:
this.ReadTextWithConverter(); ReadTextWithConverter();
break; break;
case BamlRecordType.TextWithId: case BamlRecordType.TextWithId:
this.ReadTextWithId(); ReadTextWithId();
break; break;
case BamlRecordType.PropertyWithStaticResourceId: case BamlRecordType.PropertyWithStaticResourceId:
this.ReadPropertyWithStaticResourceIdentifier(); ReadPropertyWithStaticResourceIdentifier();
break; break;
case BamlRecordType.OptimizedStaticResource: case BamlRecordType.OptimizedStaticResource:
this.ReadOptimizedStaticResource(); ReadOptimizedStaticResource();
break; break;
case BamlRecordType.KeyElementStart: case BamlRecordType.KeyElementStart:
this.ReadKeyElementStart(); ReadKeyElementStart();
break; break;
case BamlRecordType.KeyElementEnd: case BamlRecordType.KeyElementEnd:
this.ReadKeyElementEnd(); ReadKeyElementEnd();
break; break;
case BamlRecordType.PropertyTypeReference: case BamlRecordType.PropertyTypeReference:
this.ReadPropertyTypeReference(); ReadPropertyTypeReference();
break; break;
case BamlRecordType.StaticResourceStart: case BamlRecordType.StaticResourceStart:
ReadStaticResourceStart(); ReadStaticResourceStart();
@ -399,16 +399,22 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
ReadStaticResourceId(); ReadStaticResourceId();
break; break;
case BamlRecordType.PresentationOptionsAttribute: case BamlRecordType.PresentationOptionsAttribute:
this.ReadPresentationOptionsAttribute(); ReadPresentationOptionsAttribute();
break; break;
case BamlRecordType.TypeSerializerInfo: case BamlRecordType.TypeSerializerInfo:
this.ReadTypeInfo(); ReadTypeInfo();
break;
case BamlRecordType.PropertyArrayStart:
ReadPropertyArrayStart();
break;
case BamlRecordType.PropertyArrayEnd:
ReadPropertyArrayEnd();
break; break;
default: default:
throw new NotImplementedException("UnsupportedNode: " + currentType); throw new NotImplementedException("UnsupportedNode: " + currentType);
} }
} }
void ReadConnectionId() void ReadConnectionId()
{ {
int id = reader.ReadInt32(); int id = reader.ReadInt32();
@ -453,7 +459,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if (!initialized) if (!initialized)
{ {
int startChars = reader.ReadInt32(); int startChars = reader.ReadInt32();
String type = new String(new BinaryReader(this.reader.BaseStream, Encoding.Unicode).ReadChars(startChars >> 1)); String type = new String(new BinaryReader(reader.BaseStream, Encoding.Unicode).ReadChars(startChars >> 1));
if (type != "MSBAML") if (type != "MSBAML")
throw new NotSupportedException("Not a MS BAML"); throw new NotSupportedException("Not a MS BAML");
@ -500,7 +506,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
get { get {
if (intoAttribute) return XmlNodeType.Text; if (intoAttribute) return XmlNodeType.Text;
return this.CurrentNode.NodeType; return CurrentNode.NodeType;
} }
} }
@ -513,7 +519,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
String localName = string.Empty; String localName = string.Empty;
XmlBamlNode node = this.CurrentNode; XmlBamlNode node = CurrentNode;
if (node is XmlBamlSimpleProperty) { if (node is XmlBamlSimpleProperty) {
var simpleNode = (XmlBamlSimpleProperty)node; var simpleNode = (XmlBamlSimpleProperty)node;
localName = simpleNode.LocalName; localName = simpleNode.LocalName;
@ -535,7 +541,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
else if (node is XmlBamlElement) else if (node is XmlBamlElement)
localName = ((XmlBamlElement)node).TypeDeclaration.Name; localName = ((XmlBamlElement)node).TypeDeclaration.Name;
localName = this.NameTable.Add(localName); localName = NameTable.Add(localName);
return localName; return localName;
} }
@ -546,7 +552,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
PropertyDeclaration declaration; PropertyDeclaration declaration;
if (identifier >= 0) if (identifier >= 0)
{ {
declaration = this.propertyTable[identifier]; declaration = propertyTable[identifier];
} }
else else
{ {
@ -562,7 +568,7 @@ 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 = propertyTable[identifier];
return declaration; return declaration;
} else { } else {
identifier = (short)-identifier; identifier = (short)-identifier;
@ -586,11 +592,27 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
} }
} }
void ReadPropertyArrayStart()
{
short identifier = reader.ReadInt16();
PropertyDeclaration pd = GetPropertyDeclaration(identifier);
XmlBamlElement element = elements.Peek();
XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Array, pd);
elements.Push(property);
nodes.Enqueue(property);
}
void ReadPropertyArrayEnd()
{
CloseElement();
}
void ReadPropertyDictionaryStart() void ReadPropertyDictionaryStart()
{ {
short identifier = reader.ReadInt16(); short identifier = reader.ReadInt16();
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = GetPropertyDeclaration(identifier);
XmlBamlElement element = elements.Peek(); XmlBamlElement element = elements.Peek();
XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Dictionary, pd); XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Dictionary, pd);
elements.Push(property); elements.Push(property);
@ -610,7 +632,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if (isValueTypeId) if (isValueTypeId)
serializerTypeId = (short)(serializerTypeId & ~0x4000); serializerTypeId = (short)(serializerTypeId & ~0x4000);
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = GetPropertyDeclaration(identifier);
string value; string value;
switch (serializerTypeId) switch (serializerTypeId)
{ {
@ -625,16 +647,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
short typeIdentifier = reader.ReadInt16(); short typeIdentifier = reader.ReadInt16();
if (isValueTypeId) if (isValueTypeId)
{ {
TypeDeclaration typeDeclaration = this.GetTypeDeclaration(typeIdentifier); TypeDeclaration typeDeclaration = GetTypeDeclaration(typeIdentifier);
string name = reader.ReadString(); string name = reader.ReadString();
value = FormatPropertyDeclaration(new PropertyDeclaration(name, typeDeclaration), true, false, true); value = FormatPropertyDeclaration(new PropertyDeclaration(name, typeDeclaration), true, false, true);
} }
else else
value = FormatPropertyDeclaration(this.GetPropertyDeclaration(typeIdentifier), true, false, true); value = FormatPropertyDeclaration(GetPropertyDeclaration(typeIdentifier), true, false, true);
break; break;
case 0x2ea: case 0x2ea:
value = ((IFormattable)staticConvertCustomBinaryToObjectMethod.Invoke(null, new object[] { this.reader })).ToString("G", CultureInfo.InvariantCulture); value = ((IFormattable)staticConvertCustomBinaryToObjectMethod.Invoke(null, new object[] { reader })).ToString("G", CultureInfo.InvariantCulture);
break; break;
case 0x2eb: case 0x2eb:
case 0x2f0: case 0x2f0:
@ -682,7 +704,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
} }
} }
String Deserialize3DPoints() string Deserialize3DPoints()
{ {
using (StringWriter writer = new StringWriter()) using (StringWriter writer = new StringWriter())
{ {
@ -745,36 +767,36 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
bool isStaticType = (x & 0x2000) == 0x2000; bool isStaticType = (x & 0x2000) == 0x2000;
x = (short)(x & 0xfff); x = (short)(x & 0xfff);
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = GetPropertyDeclaration(identifier);
short extensionIdentifier = (short)-(x & 0xfff); short extensionIdentifier = (short)-(x & 0xfff);
string value = String.Empty; string value = String.Empty;
switch (x) { switch (x) {
case 0x25a: case 0x25a:
// StaticExtension // StaticExtension
value = this.GetStaticExtension(this.GetResourceName(valueIdentifier)); value = GetStaticExtension(GetResourceName(valueIdentifier));
break; break;
case 0x25b: // StaticResource case 0x25b: // StaticResource
case 0xbd: // DynamicResource case 0xbd: // DynamicResource
if (isValueType) if (isValueType)
{ {
value = this.GetTypeExtension(valueIdentifier); value = GetTypeExtension(valueIdentifier);
} }
else if (isStaticType) else if (isStaticType)
{ {
TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier); TypeDeclaration extensionDeclaration = GetTypeDeclaration(extensionIdentifier);
value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier))); value = GetExtension(extensionDeclaration, GetStaticExtension(GetResourceName(valueIdentifier)));
} }
else else
{ {
TypeDeclaration extensionDeclaration = this.GetTypeDeclaration(extensionIdentifier); TypeDeclaration extensionDeclaration = GetTypeDeclaration(extensionIdentifier);
value = GetExtension(extensionDeclaration, (string)this.stringTable[valueIdentifier]); value = GetExtension(extensionDeclaration, (string)stringTable[valueIdentifier]);
} }
break; break;
case 0x27a: case 0x27a:
// TemplateBinding // TemplateBinding
PropertyDeclaration pdValue = this.GetPropertyDeclaration(valueIdentifier); PropertyDeclaration pdValue = GetPropertyDeclaration(valueIdentifier);
value = GetTemplateBindingExtension(pdValue); value = GetTemplateBindingExtension(pdValue);
break; break;
default: default:
@ -827,7 +849,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
void EnqueueProperty(short identifier, string text) void EnqueueProperty(short identifier, string text)
{ {
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = GetPropertyDeclaration(identifier);
XmlBamlElement element = FindXmlBamlElement(); XmlBamlElement element = FindXmlBamlElement();
// if we've already read a nested element for the current element, this property must be a nested element as well // if we've already read a nested element for the current element, this property must be a nested element as well
if (HaveSeenNestedElement()) if (HaveSeenNestedElement())
@ -853,9 +875,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
short identifier = reader.ReadInt16(); short identifier = reader.ReadInt16();
reader.ReadByte(); reader.ReadByte();
string name = reader.ReadString(); string name = reader.ReadString();
TypeDeclaration declaringType = this.GetTypeDeclaration(identifier); TypeDeclaration declaringType = GetTypeDeclaration(identifier);
PropertyDeclaration property = new PropertyDeclaration(name, declaringType); PropertyDeclaration property = new PropertyDeclaration(name, declaringType);
this.propertyTable.Add(key, property); propertyTable.Add(key, property);
} }
void ReadDefAttributeKeyType() void ReadDefAttributeKeyType()
@ -886,7 +908,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
pd = new PropertyDeclaration("Name", XamlTypeDeclaration); pd = new PropertyDeclaration("Name", XamlTypeDeclaration);
break; break;
default: default:
string recordName = this.stringTable[identifier]; string recordName = stringTable[identifier];
if (recordName != "Key") throw new NotSupportedException(recordName); if (recordName != "Key") throw new NotSupportedException(recordName);
pd = new PropertyDeclaration(recordName, XamlTypeDeclaration); pd = new PropertyDeclaration(recordName, XamlTypeDeclaration);
if (keys == null) if (keys == null)
@ -908,7 +930,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
bool shared = reader.ReadBoolean(); bool shared = reader.ReadBoolean();
bool sharedSet = reader.ReadBoolean(); bool sharedSet = reader.ReadBoolean();
string text = this.stringTable[stringId]; string text = stringTable[stringId];
Debug.Print("KeyString: " + text); Debug.Print("KeyString: " + text);
if (text == null) if (text == null)
throw new NotSupportedException(); throw new NotSupportedException();
@ -922,7 +944,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
string @namespace = reader.ReadString(); string @namespace = reader.ReadString();
string[] textArray = new string[(uint)reader.ReadInt16()]; string[] textArray = new string[(uint)reader.ReadInt16()];
for (int i = 0; i < textArray.Length; i++) { for (int i = 0; i < textArray.Length; i++) {
textArray[i] = this.assemblyTable[reader.ReadInt16()]; textArray[i] = assemblyTable[reader.ReadInt16()];
} }
var namespaces = elements.Peek().Namespaces; var namespaces = elements.Peek().Namespaces;
@ -961,7 +983,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{ {
short identifier = reader.ReadInt16(); short identifier = reader.ReadInt16();
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = GetPropertyDeclaration(identifier);
XmlBamlElement element = FindXmlBamlElement(); XmlBamlElement element = FindXmlBamlElement();
XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Complex, pd); XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Complex, pd);
@ -988,7 +1010,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{ {
short identifier = reader.ReadInt16(); short identifier = reader.ReadInt16();
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = GetPropertyDeclaration(identifier);
XmlBamlElement element = FindXmlBamlElement(); XmlBamlElement element = FindXmlBamlElement();
XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.List, pd); XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.List, pd);
elements.Push(property); elements.Push(property);
@ -1130,7 +1152,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{ {
parentElement = elements.Peek(); parentElement = elements.Peek();
element = new XmlBamlElement(parentElement); element = new XmlBamlElement(parentElement);
element.Position = this.reader.BaseStream.Position; element.Position = reader.BaseStream.Position;
// Porto l'inizio del padre all'inizio del primo figlio // Porto l'inizio del padre all'inizio del primo figlio
if (parentElement.Position == 0 && complexPropertyOpened == 0) if (parentElement.Position == 0 && complexPropertyOpened == 0)
@ -1251,7 +1273,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
reader.ReadBoolean(); reader.ReadBoolean();
reader.ReadBoolean(); reader.ReadBoolean();
TypeDeclaration declaration = this.GetTypeDeclaration(typeIdentifier); TypeDeclaration declaration = GetTypeDeclaration(typeIdentifier);
XmlBamlPropertyElement property = new XmlBamlPropertyElement(elements.Peek(), PropertyType.Key, new PropertyDeclaration("Key", declaration)); XmlBamlPropertyElement property = new XmlBamlPropertyElement(elements.Peek(), PropertyType.Key, new PropertyDeclaration("Key", declaration));
property.Position = position; property.Position = position;
@ -1312,7 +1334,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
string text = reader.ReadString(); string text = reader.ReadString();
short valueIdentifier = reader.ReadInt16(); short valueIdentifier = reader.ReadInt16();
PropertyDeclaration pd = new PropertyDeclaration(this.stringTable[valueIdentifier].ToString()); PropertyDeclaration pd = new PropertyDeclaration(stringTable[valueIdentifier].ToString());
XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd); XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
property.Value = text; property.Value = text;
@ -1323,8 +1345,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
short identifier = reader.ReadInt16(); short identifier = reader.ReadInt16();
short typeIdentifier = reader.ReadInt16(); short typeIdentifier = reader.ReadInt16();
PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); PropertyDeclaration pd = GetPropertyDeclaration(identifier);
string value = this.GetTypeExtension(typeIdentifier); string value = GetTypeExtension(typeIdentifier);
XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd); XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
property.Value = value; property.Value = value;
@ -1345,7 +1367,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
else if (isStaticType) { else if (isStaticType) {
resource = GetStaticExtension(GetResourceName(typeIdentifier)); resource = GetStaticExtension(GetResourceName(typeIdentifier));
} else { } else {
resource = this.stringTable[typeIdentifier]; resource = stringTable[typeIdentifier];
} }
var lastKey = keys.LastOrDefault(); var lastKey = keys.LastOrDefault();
@ -1367,11 +1389,11 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if (resource is ResourceName) if (resource is ResourceName)
name = ((ResourceName)resource).Name; name = ((ResourceName)resource).Name;
else if (resource is PropertyDeclaration) else if (resource is PropertyDeclaration)
name = this.FormatPropertyDeclaration(((PropertyDeclaration)resource), true, false, false); name = FormatPropertyDeclaration(((PropertyDeclaration)resource), true, false, false);
else else
throw new InvalidOperationException("Invalid resource: " + resource.GetType()); throw new InvalidOperationException("Invalid resource: " + resource.GetType());
string prefix = this.LookupPrefix(XmlToClrNamespaceMapping.XamlNamespace, false); string prefix = LookupPrefix(XmlToClrNamespaceMapping.XamlNamespace, false);
if (String.IsNullOrEmpty(prefix)) if (String.IsNullOrEmpty(prefix))
return String.Format("{{Static {0}}}", name); return String.Format("{{Static {0}}}", name);
else else
@ -1385,7 +1407,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
string GetTypeExtension(short typeIdentifier) string GetTypeExtension(short typeIdentifier)
{ {
string prefix = this.LookupPrefix(XmlToClrNamespaceMapping.XamlNamespace, false); string prefix = LookupPrefix(XmlToClrNamespaceMapping.XamlNamespace, false);
if (String.IsNullOrEmpty(prefix)) if (String.IsNullOrEmpty(prefix))
return String.Format("{{Type {0}}}", FormatTypeDeclaration(GetTypeDeclaration(typeIdentifier))); return String.Format("{{Type {0}}}", FormatTypeDeclaration(GetTypeDeclaration(typeIdentifier)));
else else
@ -1395,7 +1417,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
string FormatTypeDeclaration(TypeDeclaration typeDeclaration) string FormatTypeDeclaration(TypeDeclaration typeDeclaration)
{ {
XmlToClrNamespaceMapping mapping = FindByClrNamespaceAndAssemblyName(typeDeclaration.Namespace, typeDeclaration.Assembly); XmlToClrNamespaceMapping mapping = FindByClrNamespaceAndAssemblyName(typeDeclaration.Namespace, typeDeclaration.Assembly);
string prefix = (mapping != null) ? this.LookupPrefix(mapping.XmlNamespace, false) : null; string prefix = (mapping != null) ? LookupPrefix(mapping.XmlNamespace, false) : null;
string name = typeDeclaration.Name; string name = typeDeclaration.Name;
if (name.EndsWith("Extension", StringComparison.Ordinal)) if (name.EndsWith("Extension", StringComparison.Ordinal))
name = name.Substring(0, name.Length - 9); name = name.Substring(0, name.Length - 9);
@ -1414,14 +1436,14 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
IDependencyPropertyDescriptor descriptor = null; IDependencyPropertyDescriptor descriptor = null;
bool areValidTypes = elementDeclaration.Type != null && propertyDeclaration.DeclaringType.Type != null; bool areValidTypes = elementDeclaration.Type != null && propertyDeclaration.DeclaringType.Type != null;
if (areValidTypes) if (areValidTypes)
descriptor = this.Resolver.GetDependencyPropertyDescriptor(propertyDeclaration.Name, elementDeclaration.Type, propertyDeclaration.DeclaringType.Type); descriptor = Resolver.GetDependencyPropertyDescriptor(propertyDeclaration.Name, elementDeclaration.Type, propertyDeclaration.DeclaringType.Type);
bool isDescendant = (areValidTypes && (propertyDeclaration.DeclaringType.Type.Equals(elementDeclaration.Type) || elementDeclaration.Type.IsSubclassOf(propertyDeclaration.DeclaringType.Type))); bool isDescendant = (areValidTypes && (propertyDeclaration.DeclaringType.Type.Equals(elementDeclaration.Type) || elementDeclaration.Type.IsSubclassOf(propertyDeclaration.DeclaringType.Type)));
bool isAttached = (descriptor != null && descriptor.IsAttached); bool isAttached = (descriptor != null && descriptor.IsAttached);
if (withPrefix) { if (withPrefix) {
XmlToClrNamespaceMapping mapping = FindByClrNamespaceAndAssemblyName(propertyDeclaration.DeclaringType.Namespace, propertyDeclaration.DeclaringType.Assembly); XmlToClrNamespaceMapping mapping = FindByClrNamespaceAndAssemblyName(propertyDeclaration.DeclaringType.Namespace, propertyDeclaration.DeclaringType.Assembly);
string prefix = (mapping != null) ? this.LookupPrefix(mapping.XmlNamespace, false) : null; string prefix = (mapping != null) ? LookupPrefix(mapping.XmlNamespace, false) : null;
if (!String.IsNullOrEmpty(prefix)) { if (!String.IsNullOrEmpty(prefix)) {
sb.Append(prefix); sb.Append(prefix);
@ -1442,10 +1464,10 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
short propertyId = reader.ReadInt16(); short propertyId = reader.ReadInt16();
short index = reader.ReadInt16(); short index = reader.ReadInt16();
PropertyDeclaration pd = this.GetPropertyDeclaration(propertyId); PropertyDeclaration pd = GetPropertyDeclaration(propertyId);
object staticResource = GetStaticResource(index); object staticResource = GetStaticResource(index);
string prefix = this.LookupPrefix(XmlToClrNamespaceMapping.PresentationNamespace, false); string prefix = LookupPrefix(XmlToClrNamespaceMapping.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);
XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd); XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd);
@ -1489,34 +1511,34 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{ {
string name = fullName.Substring(length + 1); string name = fullName.Substring(length + 1);
string namespaceName = fullName.Substring(0, length); string namespaceName = fullName.Substring(0, length);
declaration = new TypeDeclaration(this, this.Resolver, name, namespaceName, assemblyId); declaration = new TypeDeclaration(this, Resolver, name, namespaceName, assemblyId);
} }
else else
{ {
declaration = new TypeDeclaration(this, this.Resolver, fullName, string.Empty, assemblyId); declaration = new TypeDeclaration(this, Resolver, fullName, string.Empty, assemblyId);
} }
this.typeTable.Add(typeId, declaration); typeTable.Add(typeId, declaration);
} }
void ReadAssemblyInfo() void ReadAssemblyInfo()
{ {
short key = reader.ReadInt16(); short key = reader.ReadInt16();
string text = reader.ReadString(); string text = reader.ReadString();
this.assemblyTable.Add(key, text); assemblyTable.Add(key, text);
} }
void ReadStringInfo() void ReadStringInfo()
{ {
short key = reader.ReadInt16(); short key = reader.ReadInt16();
string text = reader.ReadString(); string text = reader.ReadString();
this.stringTable.Add(key, text); stringTable.Add(key, text);
} }
TypeDeclaration GetTypeDeclaration(short identifier) TypeDeclaration GetTypeDeclaration(short identifier)
{ {
TypeDeclaration declaration; TypeDeclaration declaration;
if (identifier >= 0) if (identifier >= 0)
declaration = this.typeTable[identifier]; declaration = typeTable[identifier];
else else
declaration = KnownInfo.KnownTypeTable[-identifier]; declaration = KnownInfo.KnownTypeTable[-identifier];
@ -1537,7 +1559,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
internal string GetAssembly(short identifier) internal string GetAssembly(short identifier)
{ {
return this.assemblyTable[identifier]; return assemblyTable[identifier];
} }
XmlBamlNode CurrentNode { XmlBamlNode CurrentNode {
@ -1549,12 +1571,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if (intoAttribute) return String.Empty; if (intoAttribute) return String.Empty;
TypeDeclaration declaration; TypeDeclaration declaration;
XmlBamlNode node = this.CurrentNode; XmlBamlNode node = CurrentNode;
if (node is XmlBamlSimpleProperty) if (node is XmlBamlSimpleProperty)
return ((XmlBamlSimpleProperty)node).NamespaceName; return ((XmlBamlSimpleProperty)node).NamespaceName;
else if (node is XmlBamlProperty) { else if (node is XmlBamlProperty) {
declaration = ((XmlBamlProperty)node).PropertyDeclaration.DeclaringType; declaration = ((XmlBamlProperty)node).PropertyDeclaration.DeclaringType;
TypeDeclaration elementDeclaration = this.readingElements.Peek().TypeDeclaration; TypeDeclaration elementDeclaration = readingElements.Peek().TypeDeclaration;
XmlToClrNamespaceMapping propertyMapping = FindByClrNamespaceAndAssemblyId(declaration); XmlToClrNamespaceMapping propertyMapping = FindByClrNamespaceAndAssemblyId(declaration);
XmlToClrNamespaceMapping elementMapping = FindByClrNamespaceAndAssemblyId(elementDeclaration); XmlToClrNamespaceMapping elementMapping = FindByClrNamespaceAndAssemblyId(elementDeclaration);
@ -1590,7 +1612,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{ {
get { get {
if (!intoAttribute) if (!intoAttribute)
return ((IXmlNamespaceResolver)this).LookupPrefix(this.NamespaceURI) ?? String.Empty; return ((IXmlNamespaceResolver)this).LookupPrefix(NamespaceURI) ?? String.Empty;
return String.Empty; return String.Empty;
} }
} }
@ -1598,7 +1620,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public override bool HasValue public override bool HasValue
{ {
get { return this.Value != null; } get { return Value != null; }
} }
/// <summary> /// <summary>
@ -1612,7 +1634,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public override string Value public override string Value
{ {
get { get {
XmlBamlNode node = this.CurrentNode; XmlBamlNode node = CurrentNode;
if (node is XmlBamlSimpleProperty) if (node is XmlBamlSimpleProperty)
return ((XmlBamlSimpleProperty)node).Value; return ((XmlBamlSimpleProperty)node).Value;
else if (node is XmlBamlProperty) else if (node is XmlBamlProperty)
@ -1646,7 +1668,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return ReadState.Initial; return ReadState.Initial;
if (reader == null) if (reader == null)
return ReadState.Closed; return ReadState.Closed;
if (this.EOF) if (EOF)
return ReadState.EndOfFile; return ReadState.EndOfFile;
return ReadState.Interactive; return ReadState.Interactive;
} }
@ -1670,12 +1692,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
string IXmlNamespaceResolver.LookupNamespace(string prefix) string IXmlNamespaceResolver.LookupNamespace(string prefix)
{ {
return this.LookupNamespace(prefix); return LookupNamespace(prefix);
} }
string IXmlNamespaceResolver.LookupPrefix(string namespaceName) string IXmlNamespaceResolver.LookupPrefix(string namespaceName)
{ {
return this.LookupPrefix(namespaceName, true); return LookupPrefix(namespaceName, true);
} }
string LookupPrefix(string namespaceName, bool useReading) string LookupPrefix(string namespaceName, bool useReading)

Loading…
Cancel
Save