public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (OptimizedStaticResourceRecord)((BamlRecordNode)node).Record;
			var key = XamlResourceKey.FindKeyInSiblings(node);

			key.StaticResources.Add(node);
			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;
		}
Beispiel #3
0
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var doc = new BamlElement(node);
			doc.Xaml = new XElement(ctx.GetPseudoName("Document"));

			HandlerMap.ProcessChildren(ctx, (BamlBlockNode)node, doc);
			return doc;
		}
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (ConnectionIdRecord)((BamlRecordNode)node).Record;

			parent.Xaml.Element.AddAnnotation(new BamlConnectionId(record.ConnectionId));

			return null;
		}
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (DeferableContentStartRecord)((BamlRecordNode)node).Record;

			Debug.Assert(record.Record == ((BamlBlockNode)parent.Node).Footer);

			return null;
		}
Beispiel #6
0
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (TextWithIdRecord)((BamlRecordNode)node).Record;

			parent.Xaml.Element.Add(ctx.ResolveString(record.ValueId));

			return null;
		}
Beispiel #7
0
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (ElementStartRecord)((BamlBlockNode)node).Header;
			var doc = new BamlElement(node);

			var elemType = ctx.ResolveType(record.TypeId);
			doc.Xaml = new XElement(elemType.ToXName(ctx));

			doc.Xaml.Element.AddAnnotation(elemType);
			parent.Xaml.Element.Add(doc.Xaml.Element);

			HandlerMap.ProcessChildren(ctx, (BamlBlockNode)node, doc);
			var key = node.Annotation as XamlResourceKey;
			if (key != null && key.KeyNode.Record != node.Record) {
				var handler = (IDeferHandler)HandlerMap.LookupHandler(key.KeyNode.Record.Type);
				var keyElem = handler.TranslateDefer(ctx, key.KeyNode, doc);

				doc.Children.Add(keyElem);
				keyElem.Parent = doc;
			}

			elemType.ResolveNamespace(doc.Xaml, ctx);
			doc.Xaml.Element.Name = elemType.ToXName(ctx);

			return doc;
		}
Beispiel #8
0
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (TextRecord)((BamlRecordNode)node).Record;

			parent.Xaml.Element.Add(record.Value);

			return null;
		}
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (DefAttributeRecord)((BamlRecordNode)node).Record;

			var attrName = ctx.ResolveString(record.NameId);
			parent.Xaml.Element.Add(new XAttribute(ctx.GetXamlNsName(attrName), record.Value));

			return null;
		}
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (LiteralContentRecord)((BamlRecordNode)node).Record;

			var elem = new XElement(ctx.GetXamlNsName("XData", parent.Xaml));
			var content = XElement.Parse(record.Value);
			elem.Add(content);

			parent.Xaml.Element.Add(elem);

			return null;
		}
		public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (DefAttributeKeyStringRecord)((BamlRecordNode)node).Record;
			var key = (XamlResourceKey)node.Annotation;

			var bamlElem = new BamlElement(node);
			bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml));
			parent.Xaml.Element.Add(bamlElem.Xaml.Element);
			bamlElem.Xaml.Element.Value = ctx.ResolveString(record.ValueId);
			key.KeyElement = bamlElem;

			return bamlElem;
		}
Beispiel #12
0
		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 TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (KeyElementStartRecord)((BamlBlockNode)node).Header;
			var key = (XamlResourceKey)node.Annotation;

			var bamlElem = new BamlElement(node);
			bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml));
			parent.Xaml.Element.Add(bamlElem.Xaml.Element);
			key.KeyElement = bamlElem;
			base.Translate(ctx, node, bamlElem);

			return bamlElem;
		}
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (ConstructorParameterTypeRecord)((BamlRecordNode)node).Record;

			var elem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml));
			elem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension

			var bamlElem = new BamlElement(node);
			bamlElem.Xaml = elem;
			parent.Xaml.Element.Add(elem);

			var type = ctx.ResolveType(record.TypeId);
			var typeName = ctx.ToString(parent.Xaml, type);
			elem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName));

			return bamlElem;
		}
		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 TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (DefAttributeKeyTypeRecord)((BamlRecordNode)node).Record;
			var type = ctx.ResolveType(record.TypeId);
			var typeName = ctx.ToString(parent.Xaml, type);
			var key = (XamlResourceKey)node.Annotation;

			var bamlElem = new BamlElement(node);
			bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml));
			parent.Xaml.Element.Add(bamlElem.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));
			bamlElem.Xaml.Element.Add(typeElem);

			key.KeyElement = bamlElem;

			return bamlElem;
		}
        public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
        {
            var record = (ConstructorParameterTypeRecord)((BamlRecordNode)node).Record;

            var elem = new XElement(ctx.GetKnownNamespace("TypeExtension", XamlContext.KnownNamespace_Xaml, parent.Xaml));

            elem.AddAnnotation(ctx.ResolveType(0xfd4d));             // Known type - TypeExtension

            var bamlElem = new BamlElement(node);

            bamlElem.Xaml = elem;
            parent.Xaml.Element.Add(elem);

            var type     = ctx.ResolveType(record.TypeId);
            var typeName = ctx.ToString(parent.Xaml, type);

            elem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName));

            return(bamlElem);
        }
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (XmlnsPropertyRecord)((BamlRecordNode)node).Record;
			foreach (var asmId in record.AssemblyIds) {
				var assembly = ctx.Baml.ResolveAssembly(asmId);
				ctx.XmlNs.Add(new NamespaceMap(record.Prefix, assembly, record.XmlNamespace));

				if (assembly is AssemblyDef) {
					foreach (var clrNs in ResolveCLRNamespaces((AssemblyDef)assembly, record.XmlNamespace))
						ctx.XmlNs.Add(new NamespaceMap(record.Prefix, assembly, record.XmlNamespace, clrNs));
				}
			}

			XName xmlnsDef;
			if (string.IsNullOrEmpty(record.Prefix))
				xmlnsDef = "xmlns";
			else
				xmlnsDef = XNamespace.Xmlns + XmlConvert.EncodeLocalName(record.Prefix);
			parent.Xaml.Element.Add(new XAttribute(xmlnsDef, ctx.GetXmlNamespace(record.XmlNamespace)));

			return null;
		}
        public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent)
        {
            var record   = (DefAttributeKeyTypeRecord)((BamlRecordNode)node).Record;
            var type     = ctx.ResolveType(record.TypeId);
            var typeName = ctx.ToString(parent.Xaml, type);
            var key      = (XamlResourceKey)node.Annotation;

            var bamlElem = new BamlElement(node);

            bamlElem.Xaml = new XElement(ctx.GetKnownNamespace("Key", XamlContext.KnownNamespace_Xaml, parent.Xaml));
            parent.Xaml.Element.Add(bamlElem.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));
            bamlElem.Xaml.Element.Add(typeElem);

            key.KeyElement = bamlElem;

            return(bamlElem);
        }
Beispiel #20
0
        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);
        }
Beispiel #22
0
        void AnalyzeBAMLElement(BAMLAnalyzer analyzer, BamlElement elem)
        {
            foreach (BamlRecord rec in elem.Body)
            {
                var prop = rec as PropertyWithConverterRecord;
                if (prop == null)
                {
                    continue;
                }

                Tuple <IDnlibDef, AttributeInfoRecord, TypeDef> attr = analyzer.ResolveAttribute(prop.AttributeId);
                string attrName = null;
                if (attr.Item2 != null)
                {
                    attrName = attr.Item2.Name;
                }
                else if (attr.Item1 != null)
                {
                    attrName = attr.Item1.Name;
                }

                if (attrName == "Attach")
                {
                    AnalyzeMessageAttach(analyzer, attr, prop.Value);
                }

                if (attrName == "Name")
                {
                    AnalyzeAutoBind(analyzer, attr, prop.Value);
                }

                if (attrName == "MethodName")
                {
                    AnalyzeActionMessage(analyzer, attr, prop.Value);
                }
            }
        }
Beispiel #23
0
        void AnalyzeBAMLElement(BAMLAnalyzer analyzer, BamlElement elem)
        {
            foreach (var rec in elem.Body)
            {
                var prop = rec as PropertyWithConverterRecord;
                if (prop == null)
                {
                    continue;
                }

                var    attr     = analyzer.ResolveAttribute(prop.AttributeId);
                string attrName = null;
                if (attr.Item2 != null)
                {
                    attrName = attr.Item2.Name;
                }
                else if (attr.Item1 != null)
                {
                    attrName = attr.Item1.Name;
                }

                if (attrName == "Attach" || (attrName == "Value" && prop.Value.Contains("Action")))
                {
                    AnalyzeMessageAttach(analyzer, attr, prop.Value);
                }

                if (attrName == "Name")
                {
                    AnalyzeAutoBind(analyzer, attr, prop.Value);
                }

                if (attrName == "MethodName")
                {
                    AnalyzeActionMessage(analyzer, attr, prop.Value);
                }
            }
        }
		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;
		}
Beispiel #25
0
        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;
		}
		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) {
			XamlResourceKey.Create(node);
			return null;
		}
		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;
		}
Beispiel #30
0
 public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
 {
     XamlResourceKey.Create(node);
     return(null);
 }
Beispiel #31
0
 public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			return null;
		}
		public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
			var record = (ContentPropertyRecord)((BamlRecordNode)node).Record;
			// TODO: What to do here?

			return null;
		}
Beispiel #34
0
 public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
 {
     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.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);
        }