Example #1
0
        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);
        }
Example #2
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   = (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);
        }
Example #4
0
 public void Run(XamlContext ctx, XDocument document)
 {
     foreach (var elem in document.Elements(ctx.GetPseudoName("Document")).Elements())
     {
         RewriteClass(ctx, elem);
     }
 }
Example #5
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 void Run(XamlContext ctx, XDocument document) {
			key = ctx.GetXamlNsName("Key");
			ctor = ctx.GetPseudoName("Ctor");

			bool doWork;
			do {
				doWork = false;
				foreach (var elem in document.Elements()) {
					doWork |= ProcessElement(ctx, elem);
				}
			} while (doWork);
		}
Example #7
0
		public void Run(XamlContext ctx, XDocument document) {
			foreach (var elem in document.Elements(ctx.GetPseudoName("Document")).ToList()) {
				if (elem.Elements().Count() != 1)
					continue;

				var docElem = elem.Elements().Single();
				foreach (var attr in elem.Attributes()) {
					Debug.Assert(attr.IsNamespaceDeclaration);
					attr.Remove();
					docElem.Add(attr);
				}
				elem.ReplaceWith(docElem);
			}
		}
        public void Run(XamlContext ctx, XDocument document)
        {
            key  = ctx.GetXamlNsName("Key");
            ctor = ctx.GetPseudoName("Ctor");

            bool doWork;

            do
            {
                doWork = false;
                foreach (var elem in document.Elements())
                {
                    doWork |= ProcessElement(ctx, elem);
                }
            } while (doWork);
        }
		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;
		}
Example #10
0
        public void Run(XamlContext ctx, XDocument document)
        {
            foreach (var elem in document.Elements(ctx.GetPseudoName("Document")).ToList())
            {
                if (elem.Elements().Count() != 1)
                {
                    continue;
                }

                var docElem = elem.Elements().Single();
                foreach (var attr in elem.Attributes())
                {
                    Debug.Assert(attr.IsNamespaceDeclaration);
                    attr.Remove();
                    docElem.Add(attr);
                }
                elem.ReplaceWith(docElem);
            }
        }
		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;
		}
Example #12
0
        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 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);
        }
		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 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 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;
		}
Example #17
0
		public void Run(XamlContext ctx, XDocument document) {
			foreach (var elem in document.Elements(ctx.GetPseudoName("Document")).Elements())
				RewriteClass(ctx, elem);
		}