public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record; var attr = ctx.ResolveProperty(record.AttributeId); var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); var elem = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); elem.Xaml = new XElement(elemAttr.ToXName(ctx, null)); elem.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(elem.Xaml.Element); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); elem.Xaml.Element.Add(typeElem); elemAttr.DeclaringType.ResolveNamespace(elem.Xaml, ctx); elem.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return(elem); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record; var attr = ctx.ResolveProperty(record.AttributeId); var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); var elem = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); elem.Xaml = new XElement(elemAttr.ToXName(ctx, null)); if (attr.ResolvedMember.FullNameIs("System.Windows.Style", "TargetType")) { parent.Xaml.Element.AddAnnotation(new TargetTypeAnnotation(type)); } elem.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(elem.Xaml.Element); var typeElem = new XElement(ctx.GetKnownNamespace("TypeExtension", XamlContext.KnownNamespace_Xaml, parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); elem.Xaml.Element.Add(typeElem); elemAttr.DeclaringType.ResolveNamespace(elem.Xaml, ctx); elem.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return(elem); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyRecord)((BamlRecordNode)node).Record; var elemType = parent.Xaml.Element.Annotation <XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); var value = XamlUtils.Escape(record.Value); parent.Xaml.Element.Add(ConstructXAttribute()); return(null); XAttribute ConstructXAttribute() { if (xamlProp.IsAttachedTo(elemType)) { return(new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, true), value)); } if (xamlProp.PropertyName == "Name" && elemType.ResolvedType.GetDefinition()?.ParentModule.IsMainModule == true) { return(new XAttribute(ctx.GetKnownNamespace("Name", XamlContext.KnownNamespace_Xaml), value)); } return(new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, false), value)); } }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyWithStaticResourceIdRecord)((BamlRecordNode)node).Record; var doc = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); doc.Xaml = new XElement(elemAttr.ToXName(ctx, null)); doc.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(doc.Xaml.Element); BamlNode found = node; XamlResourceKey key; do { key = XamlResourceKey.FindKeyInAncestors(found.Parent, out found); } while (key != null && record.StaticResourceId >= key.StaticResources.Count); if (key == null) throw new Exception("Cannot find StaticResource @" + node.Record.Position); var resNode = key.StaticResources[record.StaticResourceId]; var handler = (IDeferHandler)HandlerMap.LookupHandler(resNode.Type); var resElem = handler.TranslateDefer(ctx, resNode, doc); doc.Children.Add(resElem); resElem.Parent = doc; elemAttr.DeclaringType.ResolveNamespace(doc.Xaml, ctx); doc.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return doc; }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyRecord)((BamlRecordNode)node).Record; var elemType = parent.Xaml.Element.Annotation<XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); var value = XamlUtils.Escape(record.Value); var attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), value); parent.Xaml.Element.Add(attr); return null; }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyRecord)((BamlRecordNode)node).Record; var elemType = parent.Xaml.Element.Annotation <XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); var value = XamlUtils.Escape(record.Value); var attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), value); parent.Xaml.Element.Add(attr); return(null); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record; var attr = ctx.ResolveProperty(record.AttributeId); var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); var elem = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); elem.Xaml = new XElement(elemAttr.ToXName(ctx, null)); elem.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(elem.Xaml.Element); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); elem.Xaml.Element.Add(typeElem); elemAttr.DeclaringType.ResolveNamespace(elem.Xaml, ctx); elem.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return elem; }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyComplexStartRecord)((BamlBlockNode)node).Header; var doc = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); doc.Xaml = new XElement(elemAttr.ToXName(ctx, null)); doc.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(doc.Xaml.Element); HandlerMap.ProcessChildren(ctx, (BamlBlockNode)node, doc); elemAttr.DeclaringType.ResolveNamespace(doc.Xaml, ctx); doc.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return doc; }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyCustomRecord)((BamlRecordNode)node).Record; var serTypeId = ((short)record.SerializerTypeId & 0xfff); bool valueType = ((short)record.SerializerTypeId & 0x4000) == 0x4000; var elemType = parent.Xaml.Element.Annotation <XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); string value = Deserialize(ctx, parent.Xaml, (KnownTypes)serTypeId, record.Data); var attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), value); parent.Xaml.Element.Add(attr); return(null); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyDictionaryStartRecord)((BamlBlockNode)node).Header; var doc = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); doc.Xaml = new XElement(elemAttr.ToXName(ctx, null)); doc.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(doc.Xaml.Element); HandlerMap.ProcessChildren(ctx, (BamlBlockNode)node, doc); elemAttr.DeclaringType.ResolveNamespace(doc.Xaml, ctx); doc.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return(doc); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyRecord)((BamlRecordNode)node).Record; var elemType = parent.Xaml.Element.Annotation <XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); var value = XamlUtils.Escape(record.Value); XAttribute attr; if (xamlProp.PropertyName == "Name" && elemType.ResolvedType.GetDefinition()?.ParentModule.IsMainModule == true) { attr = new XAttribute(ctx.GetXamlNsName("Name"), value); } else { attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), value); } parent.Xaml.Element.Add(attr); return(null); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyWithStaticResourceIdRecord)((BamlRecordNode)node).Record; var doc = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); doc.Xaml = new XElement(elemAttr.ToXName(ctx, null)); doc.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(doc.Xaml.Element); BamlNode found = node; XamlResourceKey key; do { key = XamlResourceKey.FindKeyInAncestors(found.Parent, out found); } while (key != null && record.StaticResourceId >= key.StaticResources.Count); if (key == null) { throw new Exception("Cannot find StaticResource @" + node.Record.Position); } var resNode = key.StaticResources[record.StaticResourceId]; var handler = (IDeferHandler)HandlerMap.LookupHandler(resNode.Type); var resElem = handler.TranslateDefer(ctx, resNode, doc); doc.Children.Add(resElem); resElem.Parent = doc; elemAttr.DeclaringType.ResolveNamespace(doc.Xaml, ctx); doc.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return(doc); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyCustomRecord)((BamlRecordNode)node).Record; var serTypeId = ((short)record.SerializerTypeId & 0xfff); bool valueType = ((short)record.SerializerTypeId & 0x4000) == 0x4000; var elemType = parent.Xaml.Element.Annotation<XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); string value = Deserialize(ctx, parent.Xaml, (KnownTypes)serTypeId, record.Data); var attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), value); parent.Xaml.Element.Add(attr); return null; }
string Deserialize(XamlContext ctx, XElement elem, KnownTypes ser, byte[] value) { using (BinaryReader reader = new BinaryReader(new MemoryStream(value))) { switch (ser) { case KnownTypes.DependencyPropertyConverter: { if (value.Length == 2) { var property = ctx.ResolveProperty(reader.ReadUInt16()); return ctx.ToString(elem, property.ToXName(ctx, elem, false)); } else { var type = ctx.ResolveType(reader.ReadUInt16()); var name = reader.ReadString(); var typeName = ctx.ToString(elem, type); return typeName + "." + name; } } case KnownTypes.EnumConverter: { uint enumVal = reader.ReadUInt32(); // TODO: Convert to enum names return enumVal.ToString("D", CultureInfo.InvariantCulture); } case KnownTypes.BooleanConverter: { Debug.Assert(value.Length == 1); return (reader.ReadByte() == 1).ToString(CultureInfo.InvariantCulture); } case KnownTypes.XamlBrushSerializer: { switch (reader.ReadByte()) { case 1: // KnownSolidColor return string.Format(CultureInfo.InvariantCulture, "#{0:X8}", reader.ReadUInt32()); case 2: // OtherColor return reader.ReadString(); } break; } case KnownTypes.XamlPathDataSerializer: return XamlPathDeserializer.Deserialize(reader); case KnownTypes.XamlPoint3DCollectionSerializer: case KnownTypes.XamlVector3DCollectionSerializer: { var sb = new StringBuilder(); var count = reader.ReadUInt32(); for (uint i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:R},{1:R},{2:R} ", reader.ReadXamlDouble(), reader.ReadXamlDouble(), reader.ReadXamlDouble()); } return sb.ToString().Trim(); } case KnownTypes.XamlPointCollectionSerializer: { var sb = new StringBuilder(); var count = reader.ReadUInt32(); for (uint i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:R},{1:R} ", reader.ReadXamlDouble(), reader.ReadXamlDouble()); } return sb.ToString().Trim(); } case KnownTypes.XamlInt32CollectionSerializer: { var sb = new StringBuilder(); var type = (IntegerCollectionType)reader.ReadByte(); var count = reader.ReadInt32(); switch (type) { case IntegerCollectionType.Consecutive: { var start = reader.ReadInt32(); for (int i = 0; i < count; i++) sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", start + i); } break; case IntegerCollectionType.U1: { for (int i = 0; i < count; i++) sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", reader.ReadByte()); } break; case IntegerCollectionType.U2: { for (int i = 0; i < count; i++) sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", reader.ReadUInt16()); } break; case IntegerCollectionType.I4: { for (int i = 0; i < count; i++) sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", reader.ReadInt32()); } break; default: throw new NotSupportedException(type.ToString()); } return sb.ToString().Trim(); } } } throw new NotSupportedException(ser.ToString()); }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (OptimizedStaticResourceRecord)((BamlRecordNode)node).Record; var bamlElem = new BamlElement(node); object key; if (record.IsType) { var value = ctx.ResolveType(record.ValueId); var typeElem = new XElement(ctx.GetKnownNamespace("TypeExtension", XamlContext.KnownNamespace_Xaml, parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), ctx.ToString(parent.Xaml, value))); key = typeElem; } else if (record.IsStatic) { string attrName; if (record.ValueId > 0x7fff) { bool isKey = true; short bamlId = unchecked ((short)-record.ValueId); if (bamlId > 232 && bamlId < 464) { bamlId -= 232; isKey = false; } else if (bamlId > 464 && bamlId < 467) { bamlId -= 231; } else if (bamlId > 467 && bamlId < 470) { bamlId -= 234; isKey = false; } var res = ctx.Baml.KnownThings.Resources(bamlId); string name; if (isKey) { name = res.Item1 + "." + res.Item2; } else { name = res.Item1 + "." + res.Item3; } var xmlns = ctx.GetXmlNamespace("http://schemas.microsoft.com/winfx/2006/xaml/presentation"); attrName = ctx.ToString(parent.Xaml, xmlns.GetName(name)); } else { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml); attrName = ctx.ToString(parent.Xaml, xName); } var staticElem = new XElement(ctx.GetKnownNamespace("StaticExtension", XamlContext.KnownNamespace_Xaml, parent.Xaml)); staticElem.AddAnnotation(ctx.ResolveType(0xfda6)); // Known type - StaticExtension staticElem.Add(new XElement(ctx.GetPseudoName("Ctor"), attrName)); key = staticElem; } else { key = ctx.ResolveString(record.ValueId); } var extType = ctx.ResolveType(0xfda5); var resElem = new XElement(extType.ToXName(ctx)); resElem.AddAnnotation(extType); // Known type - StaticResourceExtension bamlElem.Xaml = resElem; parent.Xaml.Element.Add(resElem); var attrElem = new XElement(ctx.GetPseudoName("Ctor")); attrElem.Add(key); resElem.Add(attrElem); return(bamlElem); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyWithExtensionRecord)((BamlRecordNode)node).Record; var extTypeId = ((short)record.Flags & 0xfff); bool valTypeExt = ((short)record.Flags & 0x4000) == 0x4000; bool valStaticExt = ((short)record.Flags & 0x2000) == 0x2000; var elemType = parent.Xaml.Element.Annotation<XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); var extType = ctx.ResolveType((ushort)-extTypeId); extType.ResolveNamespace(parent.Xaml, ctx); var ext = new XamlExtension(extType); if (valTypeExt || extTypeId == (short)KnownTypes.TypeExtension) { var value = ctx.ResolveType(record.ValueId); ext.Initializer = new object[] { ctx.ToString(parent.Xaml, value) }; } else if (extTypeId == (short)KnownTypes.TemplateBindingExtension) { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml, false); ext.Initializer = new object[] { ctx.ToString(parent.Xaml, xName) }; } else if (valStaticExt || extTypeId == (short)KnownTypes.StaticExtension) { string attrName; if (record.ValueId > 0x7fff) { bool isKey = true; short bamlId = (short)-record.ValueId; if (bamlId > 232 && bamlId < 464) { bamlId -= 232; isKey = false; } else if (bamlId > 464 && bamlId < 467) { bamlId -= 231; } else if (bamlId > 467 && bamlId < 470) { bamlId -= 234; isKey = false; } var res = ctx.Baml.KnownThings.Resources(bamlId); string name; if (isKey) name = res.Item1 + "." + res.Item2; else name = res.Item1 + "." + res.Item3; var xmlns = ctx.GetXmlNamespace("http://schemas.microsoft.com/winfx/2006/xaml/presentation"); attrName = ctx.ToString(parent.Xaml, xmlns.GetName(name)); } else { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml); attrName = ctx.ToString(parent.Xaml, xName); } ext.Initializer = new object[] { attrName }; } else { ext.Initializer = new object[] { XamlUtils.Escape(ctx.ResolveString(record.ValueId)) }; } var extValue = ext.ToString(ctx, parent.Xaml); var attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), extValue); parent.Xaml.Element.Add(attr); return null; }
string Deserialize(XamlContext ctx, XElement elem, KnownTypes ser, byte[] value) { using (BinaryReader reader = new BinaryReader(new MemoryStream(value))) { switch (ser) { case KnownTypes.DependencyPropertyConverter: { if (value.Length == 2) { var property = ctx.ResolveProperty(reader.ReadUInt16()); return(ctx.ToString(elem, property.ToXName(ctx, elem, false))); } else { var type = ctx.ResolveType(reader.ReadUInt16()); var name = reader.ReadString(); var typeName = ctx.ToString(elem, type); return(typeName + "." + name); } } case KnownTypes.EnumConverter: { uint enumVal = reader.ReadUInt32(); // TODO: Convert to enum names return(enumVal.ToString("D", CultureInfo.InvariantCulture)); } case KnownTypes.BooleanConverter: { Debug.Assert(value.Length == 1); return((reader.ReadByte() == 1).ToString(CultureInfo.InvariantCulture)); } case KnownTypes.XamlBrushSerializer: { switch (reader.ReadByte()) { case 1: // KnownSolidColor return(string.Format(CultureInfo.InvariantCulture, "#{0:X8}", reader.ReadUInt32())); case 2: // OtherColor return(reader.ReadString()); } break; } case KnownTypes.XamlPathDataSerializer: return(XamlPathDeserializer.Deserialize(reader)); case KnownTypes.XamlPoint3DCollectionSerializer: case KnownTypes.XamlVector3DCollectionSerializer: { var sb = new StringBuilder(); var count = reader.ReadUInt32(); for (uint i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:R},{1:R},{2:R} ", reader.ReadXamlDouble(), reader.ReadXamlDouble(), reader.ReadXamlDouble()); } return(sb.ToString().Trim()); } case KnownTypes.XamlPointCollectionSerializer: { var sb = new StringBuilder(); var count = reader.ReadUInt32(); for (uint i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:R},{1:R} ", reader.ReadXamlDouble(), reader.ReadXamlDouble()); } return(sb.ToString().Trim()); } case KnownTypes.XamlInt32CollectionSerializer: { var sb = new StringBuilder(); var type = (IntegerCollectionType)reader.ReadByte(); var count = reader.ReadInt32(); switch (type) { case IntegerCollectionType.Consecutive: { var start = reader.ReadInt32(); for (int i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", start + i); } } break; case IntegerCollectionType.U1: { for (int i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", reader.ReadByte()); } } break; case IntegerCollectionType.U2: { for (int i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", reader.ReadUInt16()); } } break; case IntegerCollectionType.I4: { for (int i = 0; i < count; i++) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0:D}", reader.ReadInt32()); } } break; default: throw new NotSupportedException(type.ToString()); } return(sb.ToString().Trim()); } } } throw new NotSupportedException(ser.ToString()); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyWithExtensionRecord)((BamlRecordNode)node).Record; var extTypeId = ((short)record.Flags & 0xfff); bool valTypeExt = ((short)record.Flags & 0x4000) == 0x4000; bool valStaticExt = ((short)record.Flags & 0x2000) == 0x2000; var elemType = parent.Xaml.Element.Annotation <XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); var extType = ctx.ResolveType((ushort)-extTypeId); extType.ResolveNamespace(parent.Xaml, ctx); var ext = new XamlExtension(extType); if (valTypeExt || extTypeId == (short)KnownTypes.TypeExtension) { var value = ctx.ResolveType(record.ValueId); ext.Initializer = new object[] { ctx.ToString(parent.Xaml, value) }; } else if (extTypeId == (short)KnownTypes.TemplateBindingExtension) { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml, false); ext.Initializer = new object[] { ctx.ToString(parent.Xaml, xName) }; } else if (valStaticExt || extTypeId == (short)KnownTypes.StaticExtension) { string attrName; if (record.ValueId > 0x7fff) { bool isKey = true; short bamlId = (short)-record.ValueId; if (bamlId > 232 && bamlId < 464) { bamlId -= 232; isKey = false; } else if (bamlId > 464 && bamlId < 467) { bamlId -= 231; } else if (bamlId > 467 && bamlId < 470) { bamlId -= 234; isKey = false; } var res = ctx.Baml.KnownThings.Resources(bamlId); string name; if (isKey) { name = res.Item1 + "." + res.Item2; } else { name = res.Item1 + "." + res.Item3; } var xmlns = ctx.GetXmlNamespace("http://schemas.microsoft.com/winfx/2006/xaml/presentation"); attrName = ctx.ToString(parent.Xaml, xmlns.GetName(name)); } else { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml); attrName = ctx.ToString(parent.Xaml, xName); } ext.Initializer = new object[] { attrName }; } else { ext.Initializer = new object[] { XamlUtils.Escape(ctx.ResolveString(record.ValueId)) }; } var extValue = ext.ToString(ctx, parent.Xaml); var attr = new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, xamlProp.IsAttachedTo(elemType)), extValue); parent.Xaml.Element.Add(attr); return(null); }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (OptimizedStaticResourceRecord)((BamlRecordNode)node).Record; var bamlElem = new BamlElement(node); object key; if (record.IsType) { var value = ctx.ResolveType(record.ValueId); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), ctx.ToString(parent.Xaml, value))); key = typeElem; } else if (record.IsStatic) { string attrName; if (record.ValueId > 0x7fff) { bool isKey = true; short bamlId = (short)-record.ValueId; if (bamlId > 232 && bamlId < 464) { bamlId -= 232; isKey = false; } else if (bamlId > 464 && bamlId < 467) { bamlId -= 231; } else if (bamlId > 467 && bamlId < 470) { bamlId -= 234; isKey = false; } var res = ctx.Baml.KnownThings.Resources(bamlId); string name; if (isKey) name = res.Item1 + "." + res.Item2; else name = res.Item1 + "." + res.Item3; var xmlns = ctx.GetXmlNamespace("http://schemas.microsoft.com/winfx/2006/xaml/presentation"); attrName = ctx.ToString(parent.Xaml, xmlns.GetName(name)); } else { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml); attrName = ctx.ToString(parent.Xaml, xName); } var staticElem = new XElement(ctx.GetXamlNsName("StaticExtension", parent.Xaml)); staticElem.AddAnnotation(ctx.ResolveType(0xfda6)); // Known type - StaticExtension staticElem.Add(new XElement(ctx.GetPseudoName("Ctor"), attrName)); key = staticElem; } else key = ctx.ResolveString(record.ValueId); var extType = ctx.ResolveType(0xfda5); var resElem = new XElement(extType.ToXName(ctx)); resElem.AddAnnotation(extType); // Known type - StaticResourceExtension bamlElem.Xaml = resElem; parent.Xaml.Element.Add(resElem); var attrElem = new XElement(ctx.GetPseudoName("Ctor")); attrElem.Add(key); resElem.Add(attrElem); return bamlElem; }