Beispiel #1
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;
		}
		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;
		}
Beispiel #3
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 #4
0
        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);
        }
Beispiel #5
0
        public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
        {
            var record = (PresentationOptionsAttributeRecord)((BamlRecordNode)node).Record;

            var attrName = ctx.ResolveString(record.NameId);
            var attr     = new XAttribute(ctx.GetKnownNamespace(attrName, XamlContext.KnownNamespace_PresentationOptions, parent.Xaml), record.Value);

            parent.Xaml.Element.Add(attr);

            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 #7
0
        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.GetKnownNamespace("Key", XamlContext.KnownNamespace_Xaml, parent.Xaml));
            parent.Xaml.Element.Add(bamlElem.Xaml.Element);
            bamlElem.Xaml.Element.Value = ctx.ResolveString(record.ValueId);
            key.KeyElement = bamlElem;

            return(bamlElem);
        }
Beispiel #8
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.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;
		}
		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;
		}