private static IEnumerable<XamlInstruction> ParseProperties(IEnumerable<PropertyOption> options, XamlType xamlType)
        {
            foreach (var option in options)
            {
                var member = xamlType.GetMember(option.Property);
                yield return Inject.StartOfMember(member);

                var stringNode = option.Value as StringNode;
                if (stringNode != null)
                {
                    yield return Inject.Value(stringNode.Value);
                }

                yield return Inject.EndOfMember();
            }
        }
        private ProtoXamlNode ConvertAttributeToNode(XamlType containingType, UnprocessedAttribute rawAttribute)
        {
            XamlMember member;

            if (rawAttribute.Locator.IsDotted)
            {
                var ownerName = rawAttribute.Locator.Owner.PropertyName;
                var ownerPrefix = rawAttribute.Locator.Owner.Prefix;

                var owner = wiringContext.TypeContext.GetByPrefix(ownerPrefix, ownerName);

                member = owner.GetAttachableMember(rawAttribute.Locator.PropertyName);
            }
            else
            {
                member = containingType.GetMember(rawAttribute.Locator.PropertyName);
            }

            return nodeBuilder.Attribute(member, rawAttribute.Value, rawAttribute.Locator.Prefix);
        }
        // TODO: Refactor this shit.
        private ProtoXamlInstruction ConvertAttributeToNode(XamlType containingType, AttributeAssignment rawAttributeAssignment)
        {
            MutableXamlMember member;

            if (rawAttributeAssignment.Locator.IsDotted)
            {
                member = GetMemberForDottedLocator(rawAttributeAssignment.Locator);
            }
            else
            {
                if (IsNameDirective(rawAttributeAssignment.Locator, containingType))
                {
                    return instructionBuilder.Directive(CoreTypes.Name, rawAttributeAssignment.Value);
                }

                member = containingType.GetMember(rawAttributeAssignment.Locator.PropertyName);
            }

            var namespaceDeclaration = new NamespaceDeclaration(rawAttributeAssignment.Locator.Namespace, rawAttributeAssignment.Locator.Prefix);
            return instructionBuilder.Attribute(member, rawAttributeAssignment.Value, namespaceDeclaration.Prefix);
        }
        private ProtoXamlInstruction ConvertAttributeToNode(XamlType containingType, AttributeAssignment rawAttributeAssignment)
        {
            MutableXamlMember member;

            if (rawAttributeAssignment.Locator.IsDotted)
            {
                var ownerName = rawAttributeAssignment.Locator.Owner.PropertyName;
                var ownerPrefix = rawAttributeAssignment.Locator.Owner.Prefix;

                var owner = wiringContext.TypeContext.GetByPrefix(ownerPrefix, ownerName);

                member = owner.GetAttachableMember(rawAttributeAssignment.Locator.PropertyName);
            }
            else
            {
                member = containingType.GetMember(rawAttributeAssignment.Locator.PropertyName);
            }

            var namespaceDeclaration = new NamespaceDeclaration(rawAttributeAssignment.Locator.Namespace, rawAttributeAssignment.Locator.Prefix);
            return instructionBuilder.Attribute(member, rawAttributeAssignment.Value, namespaceDeclaration.Prefix);
        }
        private IEnumerable<Instruction> ParseProperties(IEnumerable<PropertyOption> options, XamlType xamlType)
        {
            foreach (var option in options)
            {
                var member = xamlType.GetMember(option.Property);
                yield return Inject.StartOfMember(member);


                var stringNode = option.Value as StringNode;
                if (stringNode != null)
                {
                    yield return Inject.Value(stringNode.Value);
                }

                var markupExtensionNode = option.Value as MarkupExtensionNode;
                if (markupExtensionNode != null)
                {
                    foreach (var xamlInstruction in ParseMarkupExtensionNode(markupExtensionNode)) { yield return xamlInstruction; }
                }

                yield return Inject.EndOfMember();
            }
        }
		void ProcessAttributesToMember (XamlSchemaContext sctx, StartTagInfo sti, XamlType xt)
		{
			foreach (var p in sti.Attributes) {
				int idx = p.Key.IndexOf (':');
				string prefix = idx > 0 ? p.Key.Substring (0, idx) : String.Empty;
				string aname = idx > 0 ? p.Key.Substring (idx + 1) : p.Key;
				idx = aname.IndexOf ('.');
				if (idx > 0) {
					string apns = prefix.Length > 0 ? r.LookupNamespace (prefix) : r.NamespaceURI;
					var apname = aname.Substring (0, idx);
					var axtn = new XamlTypeName (apns, apname, null);
					var at = sctx.GetXamlType (axtn);
					var am = at.GetAttachableMember (aname.Substring (idx + 1));
					if (am != null)
						sti.Members.Add (new Pair (am, p.Value));
					// ignore unknown attribute
				}
				var xm = xt.GetMember (aname);
				if (xm != null)
					sti.Members.Add (new Pair (xm, p.Value));
				// ignore unknown attribute
			}
		}
Example #7
0
		public void ReadOnlyPropertyContainer ()
		{
			var xt = new XamlType (typeof (ReadOnlyPropertyContainer), sctx);
			var xm = xt.GetMember ("Bar");
			Assert.IsNotNull (xm, "#1");
			Assert.IsFalse (xm.IsWritePublic, "#2");
		}
Example #8
0
		public void ContentIncluded ()
		{
			var xt = new XamlType (typeof (ContentIncludedClass), sctx);
			var xm = xt.GetMember ("Content");
			Assert.AreEqual (xm, xt.ContentProperty, "#1");
			Assert.IsTrue (xt.GetAllMembers ().Contains (xm), "#2");
		}
Example #9
0
		public void ListMembers ()
		{
			var xt = new XamlType (typeof (List<int>), sctx);
			var ml = xt.GetAllMembers ().ToArray ();
			Assert.AreEqual (1, ml.Length, "#1");
			Assert.IsNotNull (xt.GetMember ("Capacity"), "#2");
		}
Example #10
0
		protected void WriteNullMemberAsObject (XamlReader r, Action validateNullInstance)
		{
			Assert.AreEqual (XamlNodeType.None, r.NodeType, "#1");
			Assert.IsTrue (r.Read (), "#6");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#7");
			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "#7-2");
			Assert.AreEqual ("clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name, r.Namespace.Namespace, "#7-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#12-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#12-3");

			Assert.IsTrue (r.Read (), "#16");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#17");
			var xt = new XamlType (typeof (TestClass4), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#17-2");
//			Assert.IsTrue (r.Instance is TestClass4, "#17-3");
			Assert.AreEqual (2, xt.GetAllMembers ().Count, "#17-4");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#22");
			Assert.AreEqual (xt.GetMember ("Bar"), r.Member, "#22-2");

			Assert.IsTrue (r.Read (), "#26");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#27");
			Assert.AreEqual (XamlLanguage.Null, r.Type, "#27-2");
			if (validateNullInstance != null)
				validateNullInstance ();

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#32");

			Assert.IsTrue (r.Read (), "#36");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#37");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#42");
			Assert.AreEqual (xt.GetMember ("Foo"), r.Member, "#42-2");

			Assert.IsTrue (r.Read (), "#43");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#43-2");
			Assert.AreEqual (XamlLanguage.Null, r.Type, "#43-3");
			if (validateNullInstance != null)
				validateNullInstance ();

			Assert.IsTrue (r.Read (), "#44");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#44-2");

			Assert.IsTrue (r.Read (), "#46");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#47");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#52");

			Assert.IsFalse (r.Read (), "#56");
			Assert.IsTrue (r.IsEof, "#57");
		}
Example #11
0
		protected void Read_ArrayOrArrayExtensionOrMyArrayExtension (XamlReader r, Action validateInstance, Type extType)
		{
			if (extType == typeof (MyArrayExtension)) {
				Assert.IsTrue (r.Read (), "#1");
				Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#2");
				Assert.IsNotNull (r.Namespace, "#3");
				Assert.AreEqual (String.Empty, r.Namespace.Prefix, "#3-2");
			}
			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (extType, r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
			if (validateInstance != null)
				validateInstance ();

			if (r is XamlXmlReader)
				ReadBase (r);

			// This assumption on member ordering ("Type" then "Items") is somewhat wrong, and we might have to adjust it in the future.

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Type"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("x:Int32", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#61");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#62");
			Assert.AreEqual (xt.GetMember ("Items"), r.Member, "#63");

			Assert.IsTrue (r.Read (), "#71");
			Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "#71-2");
			Assert.IsNull (r.Type, "#71-3");
			Assert.IsNull (r.Member, "#71-4");
			Assert.IsNull (r.Value, "#71-5");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"5", "-3", "0"};
			for (int i = 0; i < 3; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				Assert.AreEqual (XamlLanguage.Initialization, r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#75-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items

			Assert.IsTrue (r.Read (), "#83");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#84"); // GetObject

			Assert.IsTrue (r.Read (), "#85");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#86"); // ArrayExtension.Items

			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88"); // ArrayExtension

			Assert.IsFalse (r.Read (), "#89");
		}
Example #12
0
		protected void Read_NonPrimitive (XamlReader r)
		{
			Assert.AreEqual (XamlNodeType.None, r.NodeType, "#1");
			Assert.IsTrue (r.Read (), "#6");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#7");
			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "#7-2");
			Assert.AreEqual ("clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name, r.Namespace.Namespace, "#7-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#12-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#12-3");

			Assert.IsTrue (r.Read (), "#16");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#17");
			var xt = new XamlType (typeof (TestClass3), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#17-2");
//			Assert.IsTrue (r.Instance is TestClass3, "#17-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#22");
			Assert.AreEqual (xt.GetMember ("Nested"), r.Member, "#22-2");

			Assert.IsTrue (r.Read (), "#26");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#27");
			Assert.AreEqual (XamlLanguage.Null, r.Type, "#27-2");
//			Assert.IsNull (r.Instance, "#27-3");

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#32");

			Assert.IsTrue (r.Read (), "#36");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#37");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#42");

			Assert.IsFalse (r.Read (), "#46");
			Assert.IsTrue (r.IsEof, "#47");
		}
Example #13
0
		protected void Read_CollectionContentPropertyX (XamlReader r, bool contentPropertyIsUsed)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("sc", r.Namespace.Prefix, "ns#2-4");
			assns = "clr-namespace:System.Collections;assembly=" + typeof (IList<>).Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#2-5");

			Assert.IsTrue (r.Read (), "ns#x-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#x-2");
			Assert.IsNotNull (r.Namespace, "ns#x-3");
			Assert.AreEqual ("scg", r.Namespace.Prefix, "ns#x-4");
			assns = "clr-namespace:System.Collections.Generic;assembly=" + typeof (IList<>).Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#x-5");

			Assert.IsTrue (r.Read (), "ns#3-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#3-2");
			Assert.IsNotNull (r.Namespace, "ns#3-3");
			Assert.AreEqual ("x", r.Namespace.Prefix, "ns#3-4");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "ns#3-5");

			// t:CollectionContentProperty
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (CollectionContentPropertyX), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:ListOfItems
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("ListOfItems"), r.Member, "sm1#3");

			// t:List<IEnumerable>
			xt = new XamlType (typeof (List<IEnumerable>), r.SchemaContext);
			Assert.IsTrue (r.Read (), "so#2-1");

			if (false/*contentPropertyIsUsed*/)
				Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "so#2-2.1");
			else {
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#2-2.2");
				Assert.AreEqual (xt, r.Type, "so#2-3");

				// m:Capacity
				Assert.IsTrue (r.Read (), "sm#2-1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#2-2");
				Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "sm#2-3");

				// r.Skip (); // LAMESPEC: .NET then skips to *post* Items node (i.e. at the first TestClass item)

				Assert.IsTrue (r.Read (), "v#1-1");

				// /m:Capacity
				Assert.IsTrue (r.Read (), "em#2-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2");
			}

			Assert.IsTrue (r.Read (), "sm#3-1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#3-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "sm#3-3");

			if (!contentPropertyIsUsed) {

				Assert.IsTrue (r.Read (), "so#x-1");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#x-2.2");
				xt = new XamlType (typeof (List<object>), r.SchemaContext);
				Assert.AreEqual (xt, r.Type, "so#x-3");

				// m:Capacity
				Assert.IsTrue (r.Read (), "sm#xx-1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#xx-2");
				Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "sm#xx-3");

				Assert.IsTrue (r.Read (), "v#x-1");

				// /m:Capacity
				Assert.IsTrue (r.Read (), "em#xx-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#xx-2");

				Assert.IsTrue (r.Read (), "sm#x-1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#x-2");
				Assert.AreEqual (XamlLanguage.Items, r.Member, "sm#x-3");
			}

			for (int i = 0; i < 4; i++) {
				// t:SimpleClass
				Assert.IsTrue (r.Read (), "so#3-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#3-2." + i);
				xt = new XamlType (typeof (SimpleClass), r.SchemaContext);
				Assert.AreEqual (xt, r.Type, "so#3-3." + i);

				// /t:SimpleClass
				Assert.IsTrue (r.Read (), "eo#3-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#3-2");
			}

			if (!contentPropertyIsUsed) {
				// /m:Items
				Assert.IsTrue (r.Read (), "em#x-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#x-2");

				// /t:List<IEnumerable>
				Assert.IsTrue (r.Read (), "eo#x-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#x-2");
			}

			// /m:Items
			Assert.IsTrue (r.Read (), "em#3-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#3-2");

			// /t:CollectionContentProperty
			Assert.IsTrue (r.Read (), "eo#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#2-2");

			// /m:ListOfItems
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:CollectionContentProperty
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
Example #14
0
		protected void Read_TypeConverterOnListMember (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			Assert.AreEqual ("http://www.domain.com/path", r.Namespace.Namespace, "ns#1-5");

			// t:TypeOtherAssembly
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (SecondTest.TypeOtherAssembly), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Values
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Values"), r.Member, "sm1#3");

			// x:Value
			Assert.IsTrue (r.Read (), "v#1-1");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#1-2");
			Assert.AreEqual ("1, 2, 3", r.Value, "v#1-3");

			// /m:Values
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:TypeOtherAssembly
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
Example #15
0
		protected void Read_XmlSerializableWrapper (XamlReader r, bool isObjectReader)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("x", r.Namespace.Prefix, "ns#2-4");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "ns#2-5");

			// t:XmlSerializableWrapper
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (XmlSerializableWrapper), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Value
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Value"), r.Member, "sm1#3");

			// x:XData
			Assert.IsTrue (r.Read (), "so#2-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#2-2");
			Assert.AreEqual (XamlLanguage.XData, r.Type, "so#2-3");
			if (r is XamlObjectReader)
				Assert.IsNull (((XamlObjectReader) r).Instance, "xdata-instance");

			Assert.IsTrue (r.Read (), "sm2#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm2#2");
			Assert.AreEqual (XamlLanguage.XData.GetMember ("Text"), r.Member, "sm2#3");

			Assert.IsTrue (r.Read (), "v1#1");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v1#2");
			var val = isObjectReader ? "<root />" : "<root xmlns=\"" + assns + "\" />";
			Assert.AreEqual (val, r.Value, "v1#3");

			Assert.IsTrue (r.Read (), "em2#1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em2#2");

			Assert.IsTrue (r.Read (), "eo#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#2-2");

			Assert.IsTrue (r.Read (), "em1#1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em1#2");

			// /t:XmlSerializableWrapper
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
Example #16
0
		protected void Read_ListArray (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");

			var defns = "clr-namespace:System.Collections.Generic;assembly=mscorlib";
			var defns2 = "clr-namespace:System;assembly=mscorlib";
			var defns3 = "clr-namespace:System.Xaml;assembly=System.Xaml";

			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "ns#1-3");
			Assert.AreEqual (defns, r.Namespace.Namespace, "ns#1-4");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("s", r.Namespace.Prefix, "ns#2-3-2");
			Assert.AreEqual (defns2, r.Namespace.Namespace, "ns#2-3-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (List<Array>), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
			Assert.IsTrue (xt.IsCollection, "#27");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("2", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"x:Int32", "x:String"};
			for (int i = 0; i < 2; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.AreEqual (XamlLanguage.Array, r.Type, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				Assert.AreEqual (XamlLanguage.Array.GetMember ("Type"), r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");

				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#75-2");
				Assert.AreEqual (XamlLanguage.Array.GetMember ("Items"), r.Member, i + "#75-3");
				Assert.IsTrue (r.Read (), i + "#75-4");
				Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, i + "#75-5");
				Assert.IsTrue (r.Read (), i + "#75-7");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#75-8");
				Assert.AreEqual (XamlLanguage.Items, r.Member, i + "#75-9");

				for (int j = 0; j < 3; j++) {
					Assert.IsTrue (r.Read (), i + "#76-" + j);
					Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#76-2"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-3"+ "-" + j);
					Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#76-4"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-5"+ "-" + j);
					Assert.AreEqual (XamlNodeType.Value, r.NodeType, i + "#76-6"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-7"+ "-" + j);
					Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#76-8"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-9"+ "-" + j);
					Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#76-10"+ "-" + j);
				}

				Assert.IsTrue (r.Read (), i + "#77");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#77-2");

				Assert.IsTrue (r.Read (), i + "#78");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#78-2");

				Assert.IsTrue (r.Read (), i + "#79");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#79-2");

				Assert.IsTrue (r.Read (), i + "#80");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#80-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items
			
			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88");

			Assert.IsFalse (r.Read (), "#89");
		}
Example #17
0
		protected void Read_ArrayList (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");

			var defns = "clr-namespace:System.Collections;assembly=mscorlib";

			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "ns#1-3");
			Assert.AreEqual (defns, r.Namespace.Namespace, "ns#1-4");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (ArrayList), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
//			Assert.AreEqual (obj, r.Instance, "#26");
			Assert.IsTrue (xt.IsCollection, "#27");

			if (r is XamlXmlReader)
				ReadBase (r);

			// This assumption on member ordering ("Type" then "Items") is somewhat wrong, and we might have to adjust it in the future.

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			// The value is implementation details, not testable.
			//Assert.AreEqual ("3", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"5", "-3", "0"};
			for (int i = 0; i < 3; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				Assert.AreEqual (XamlLanguage.Initialization, r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#75-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items

			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88");

			Assert.IsFalse (r.Read (), "#89");
		}
Example #18
0
		void ReadTestProperty_AmbientPropertyContainer (XamlReader r, int i, bool extensionBased)
		{
			var xt = new XamlType (typeof (SecondTest.TestObject), r.SchemaContext);

			// m:TestProperty
			Assert.IsTrue (r.Read (), "sm#2-1." + i);
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#2-2." + i);
			Assert.AreEqual (xt.GetMember ("TestProperty"), r.Member, "sm#2-3." + i);

			if (i == 0) {
				// t:TestObject={x:Null}
				Assert.IsTrue (r.Read (), "so#3-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#3-2." + i);
				Assert.AreEqual (XamlLanguage.Null, r.Type, "so#3-3." + i);
				Assert.IsTrue (r.Read (), "eo#3-1." + i);
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#3-2." + i);
			} else if (extensionBased) {
				ReadReasourceExtension_AmbientPropertyContainer (r, i, extensionBased);
			} else {
				ReadReference_AmbientPropertyContainer (r, i, extensionBased);
			}

			// /m:TestProperty
			Assert.IsTrue (r.Read (), "em#2-1." + i);
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2." + i);
		}
Example #19
0
		// It gives Type member, not PositionalParameters... and no Items member here.
		protected void Read_ArrayExtension2 (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");
//			Assert.IsNull (r.Instance, "#14");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (ArrayExtension), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23-2");
//			Assert.IsTrue (r.Instance is ArrayExtension, "#26");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Type"), r.Member, "#33-2");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("x:Int32", r.Value, "#43-2");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#61");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#62");

			Assert.IsFalse (r.Read (), "#71");
			Assert.IsTrue (r.IsEof, "#72");
		}
Example #20
0
		protected void Read_NullableContainer (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			// t:NullableContainer
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (NullableContainer), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:TestProp
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("TestProp"), r.Member, "sm1#3");

			// x:Value
			Assert.IsTrue (r.Read (), "v#1-1");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#1-2");
			Assert.AreEqual ("5", r.Value, "v#1-3");

			// /m:TestProp
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:NullableContainer
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
Example #21
0
		public void Dictionary ()
		{
			var t = new XamlType (typeof (int), sctx);
			Assert.IsFalse (t.IsDictionary, "#1.1");
			Assert.IsFalse (t.IsCollection, "#1.1-2");
			Assert.IsNull (t.KeyType, "#1.2");
			t = new XamlType (typeof (Hashtable), sctx);
			Assert.IsTrue (t.IsDictionary, "#2.1");
			Assert.IsFalse (t.IsCollection, "#2.1-2");
			Assert.IsNotNull (t.KeyType, "#2.2");
			Assert.IsNotNull (t.ItemType, "#2.2-2");
			Assert.AreEqual ("Object", t.KeyType.Name, "#2.3");
			Assert.AreEqual ("Object", t.ItemType.Name, "#2.3-2");
			t = new XamlType (typeof (Dictionary<int,string>), sctx);
			Assert.IsTrue (t.IsDictionary, "#3.1");
			Assert.IsFalse (t.IsCollection, "#3.1-2");
			Assert.IsNotNull (t.KeyType, "#3.2");
			Assert.IsNotNull (t.ItemType, "#3.2-2");
			Assert.AreEqual ("Int32", t.KeyType.Name, "#3.3");
			Assert.AreEqual ("String", t.ItemType.Name, "#3.3-2");

			var ml = t.GetAllMembers ();
			Assert.AreEqual (2, ml.Count, "#3.4");
			Assert.IsTrue (ml.Any (mi => mi.Name == "Keys"), "#3.4-2");
			Assert.IsTrue (ml.Any (mi => mi.Name == "Values"), "#3.4-3");
			Assert.IsNotNull (t.GetMember ("Keys"), "#3.4-4");
			Assert.IsNotNull (t.GetMember ("Values"), "#3.4-5");
		}
Example #22
0
		protected void Read_DirectListContainer (XamlReader r)
		{
			var assns1 = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			var assns2 = "clr-namespace:System.Collections.Generic;assembly=" + typeof (IList<>).Assembly.GetName ().Name;
			ReadNamespace (r, String.Empty, assns1, "ns#1");
			ReadNamespace (r, "scg", assns2, "ns#2");
			ReadNamespace (r, "x", XamlLanguage.Xaml2006Namespace, "ns#3");

			// t:DirectListContainer
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (DirectListContainer), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Items
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Items"), r.Member, "sm1#3");

			// GetObject
			Assert.IsTrue (r.Read (), "go#1");
			Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "go#2");

			// m:Items(GetObject)
			Assert.IsTrue (r.Read (), "sm2#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm2#2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "sm2#3");

			xt = r.SchemaContext.GetXamlType (typeof (DirectListContent));
			for (int i = 0; i < 3; i++) {
				// t:DirectListContent
				Assert.IsTrue (r.Read (), "so#x-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#x-2." + i);
				Assert.AreEqual (xt, r.Type, "so#x-3." + i);

				// m:Value
				Assert.IsTrue (r.Read (), "sm#x1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#x2");
				Assert.AreEqual (xt.GetMember ("Value"), r.Member, "sm#x3");

				// x:Value
				Assert.IsTrue (r.Read (), "v#x-1");
				Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#x-2");
				Assert.AreEqual ("Hello" + (i + 1), r.Value, "v#x-3");

				// /m:Value
				Assert.IsTrue (r.Read (), "em#x-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#x-2");

				// /t:DirectListContent
				Assert.IsTrue (r.Read (), "eo#x-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#x-2");
			}

			// /m:Items(GetObject)
			Assert.IsTrue (r.Read (), "em#2-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2");

			// /GetObject
			Assert.IsTrue (r.Read (), "ego#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "ego#2-2");

			// /m:Items
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:DirectListContainer
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
Example #23
0
		public void CustomArrayExtension ()
		{
			var xt = new XamlType (typeof (MyArrayExtension), sctx);
			var xm = xt.GetMember ("Items");
			Assert.IsNotNull (xt.GetAllMembers ().FirstOrDefault (m => m.Name == "Items"), "#0");
			Assert.IsNotNull (xm, "#1");
			Assert.IsFalse (xm.IsReadOnly, "#2"); // Surprisingly it is False. Looks like XAML ReadOnly is true only if it lacks set accessor. Having private member does not make it ReadOnly.
			Assert.IsTrue (xm.Type.IsCollection, "#3");
			Assert.IsFalse (xm.Type.IsConstructible, "#4");
		}
Example #24
0
		protected void Read_DirectDictionaryContainer (XamlReader r)
		{
			var assns1 = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			ReadNamespace (r, String.Empty, assns1, "ns#1");
			ReadNamespace (r, "x", XamlLanguage.Xaml2006Namespace, "ns#2");

			// t:DirectDictionaryContainer
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (DirectDictionaryContainer), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Items
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Items"), r.Member, "sm1#3");

			// GetObject
			Assert.IsTrue (r.Read (), "go#1");
			Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "go#2");

			// m:Items(GetObject)
			Assert.IsTrue (r.Read (), "sm2#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm2#2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "sm2#3");

			xt = r.SchemaContext.GetXamlType (typeof (int));
			for (int i = 0; i < 3; i++) {
				// t:DirectDictionaryContent
				Assert.IsTrue (r.Read (), "so#x-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#x-2." + i);
				Assert.AreEqual (xt, r.Type, "so#x-3." + i);

				// m:Key
				Assert.IsTrue (r.Read (), "sm#y1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#y2");
				Assert.AreEqual (XamlLanguage.Key, r.Member, "sm#y3");

				// x:Value
				Assert.IsTrue (r.Read (), "v#y-1");
				Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#y-2");
				Assert.AreEqual (((EnumValueType) i).ToString ().ToLower (), r.Value, "v#y-3");

				// /m:Key
				Assert.IsTrue (r.Read (), "em#y-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#y-2");

				// m:Value
				Assert.IsTrue (r.Read (), "sm#x1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#x2");
				Assert.AreEqual (XamlLanguage.Initialization, r.Member, "sm#x3");

				// x:Value
				Assert.IsTrue (r.Read (), "v#x-1");
				Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#x-2");
				Assert.AreEqual ("" + (i + 2) * 10, r.Value, "v#x-3");

				// /m:Value
				Assert.IsTrue (r.Read (), "em#x-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#x-2");

				// /t:DirectDictionaryContent
				Assert.IsTrue (r.Read (), "eo#x-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#x-2");
			}

			// /m:Items(GetObject)
			Assert.IsTrue (r.Read (), "em#2-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2");

			// /GetObject
			Assert.IsTrue (r.Read (), "ego#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "ego#2-2");

			// /m:Items
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:DirectDictionaryContainer
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
Example #25
0
		public void NamedItem ()
		{
			var xt = new XamlType (typeof (NamedItem), sctx);
			var e = xt.GetAllMembers ().GetEnumerator ();
			Assert.IsTrue (e.MoveNext (), "#1");
			Assert.AreEqual (xt.GetMember ("ItemName"), e.Current, "#2");
			Assert.IsTrue (e.MoveNext (), "#3");
			Assert.AreEqual (xt.GetMember ("References"), e.Current, "#4");
			Assert.IsFalse (e.MoveNext (), "#5");
		}
Example #26
0
		protected void Read_AttachedProperty (XamlReader r)
		{
			var at = new XamlType (typeof (Attachable), r.SchemaContext);

			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			// t:AttachedWrapper
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (AttachedWrapper), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			ReadAttachedProperty (r, at.GetAttachableMember ("Foo"), "x", "x");

			// m:Value
			Assert.IsTrue (r.Read (), "sm#2-1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#sm#2-2");
			Assert.AreEqual (xt.GetMember ("Value"), r.Member, "sm#2-3");

			// t:Attached
			Assert.IsTrue (r.Read (), "so#2-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#so#2-2");
			Assert.AreEqual (r.SchemaContext.GetXamlType (typeof (Attached)), r.Type, "so#2-3");

			ReadAttachedProperty (r, at.GetAttachableMember ("Foo"), "y", "y");

			Assert.IsTrue (r.Read (), "eo#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#eo#2-2");

			// /m:Value
			Assert.IsTrue (r.Read (), "em#2-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#em#2-2");

			// /t:AttachedWrapper
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
		// Note that it could return invalid (None) node to tell the caller that it is not really an object element.
		IEnumerable<XamlXmlNodeInfo> ReadObjectElement (XamlType parentType, XamlMember currentMember)
		{
			if (r.NodeType != XmlNodeType.Element) {
				//throw new XamlParseException (String.Format ("Element is expected, but got {0}", r.NodeType));
				yield return Node (XamlNodeType.Value, r.Value);
				yield break;
			}

			if (r.MoveToFirstAttribute ()) {
				do {
					if (r.NamespaceURI == XamlLanguage.Xmlns2000Namespace)
						yield return Node (XamlNodeType.NamespaceDeclaration, new NamespaceDeclaration (r.Value, r.Prefix == "xmlns" ? r.LocalName : String.Empty));
				} while (r.MoveToNextAttribute ());
				r.MoveToElement ();
			}

			var sti = GetStartTagInfo ();

			var xt = sctx.GetXamlType (sti.TypeName);
			if (xt == null) {
				// Current element could be for another member in the parent type (if exists)
				if (parentType != null && (r.LocalName.IndexOf ('.') > 0 || parentType.GetMember (r.LocalName) != null)) {
					// stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
					yield return Node (XamlNodeType.None, null);
					yield break;
				}

				// creates name-only XamlType. Also, it does not seem that it does not store this XamlType to XamlSchemaContext (Try GetXamlType(xtn) after reading such xaml node, it will return null).
				xt = new XamlType (sti.Namespace, sti.Name, sti.TypeName.TypeArguments == null ? null : sti.TypeName.TypeArguments.Select<XamlTypeName,XamlType> (xxtn => sctx.GetXamlType (xxtn)).ToArray (), sctx);
			}
			
			bool isGetObject = false;
			if (currentMember != null && !xt.CanAssignTo (currentMember.Type)) {
				if (currentMember.DeclaringType != null && currentMember.DeclaringType.ContentProperty == currentMember)
					isGetObject = true;

				// It could still be GetObject if current_member
				// is not a directive and current type is not
				// a markup extension.
				// (I'm not very sure about the condition;
				// it could be more complex.)
				// seealso: bug #682131
				else if (!(currentMember is XamlDirective) &&
				    !xt.IsMarkupExtension)
					isGetObject = true;
			}

			if (isGetObject) {
				yield return Node (XamlNodeType.GetObject, currentMember.Type);
				foreach (var ni in ReadMembers (parentType, currentMember.Type))
					yield return ni;
				yield return Node (XamlNodeType.EndObject, currentMember.Type);
				yield break;
			}
			// else

			yield return Node (XamlNodeType.StartObject, xt);

			// process attribute members (including MarkupExtensions)
			ProcessAttributesToMember (sctx, sti, xt);

			foreach (var pair in sti.Members) {
				yield return Node (XamlNodeType.StartMember, pair.Key);

				// Try markup extension
				// FIXME: is this rule correct?
				var v = pair.Value;
				if (!String.IsNullOrEmpty (v) && v [0] == '{') {
					var pai = ParsedMarkupExtensionInfo.Parse (v, xaml_namespace_resolver, sctx);
					yield return Node (XamlNodeType.StartObject, pai.Type);
					foreach (var xepair in pai.Arguments) {
						yield return Node (XamlNodeType.StartMember, xepair.Key);
						if (xepair.Value is List<string>)
							foreach (var s in (List<string>) xepair.Value)
								yield return Node (XamlNodeType.Value, s);
						else
							yield return Node (XamlNodeType.Value, xepair.Value);
						yield return Node (XamlNodeType.EndMember, xepair.Key);
					}
					yield return Node (XamlNodeType.EndObject, pai.Type);
				}
				else
					yield return Node (XamlNodeType.Value, pair.Value);

				yield return Node (XamlNodeType.EndMember, pair.Key);
			}

			// process content members
			if (!r.IsEmptyElement) {
				r.Read ();
				foreach (var ni in ReadMembers (parentType, xt))
					yield return ni;
				r.ReadEndElement ();
			}
			else
				r.Read (); // consume empty element.

			yield return Node (XamlNodeType.EndObject, xt);
		}
Example #28
0
		protected void Read_Reference (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (Reference), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23-2");
//			Assert.IsTrue (r.Instance is Reference, "#26");
			Assert.IsNotNull (XamlLanguage.Type.SchemaContext, "#23-3");
			Assert.IsNotNull (r.SchemaContext, "#23-4");
			Assert.AreNotEqual (XamlLanguage.Type.SchemaContext, r.SchemaContext, "#23-5");
			Assert.AreNotEqual (XamlLanguage.Reference.SchemaContext, xt.SchemaContext, "#23-6");
			Assert.AreEqual (XamlLanguage.Reference, xt, "#23-7");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			// unlike TypeExtension there is no PositionalParameters.
			Assert.AreEqual (xt.GetMember ("Name"), r.Member, "#33-2");

			// It is a ContentProperty (besides [ConstructorArgument])
			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("FooBar", r.Value, "#43-2");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#61");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#62");

			Assert.IsFalse (r.Read (), "#71");
			Assert.IsTrue (r.IsEof, "#72");
		}
		// member element, implicit member, children via content property, or value
		IEnumerable<XamlXmlNodeInfo> ReadMemberElement (XamlType parentType, XamlType xt)
		{
			XamlMember xm = null;
			var name = r.LocalName;
			int idx = name.IndexOf ('.');
			// FIXME: it skips strict type name check, as it could result in MarkupExtension mismatch (could be still checked, though)
			if (idx >= 0/* && name.Substring (0, idx) == xt.Name*/) {
				name = name.Substring (idx + 1);
				xm = xt.GetMember (name);
			} else {
				xm = (XamlMember) FindStandardDirective (name, AllowedMemberLocations.MemberElement) ??
					// not a standard directive? then try attachable
					xt.GetAttachableMember (name) ??
					// still not? then try ordinal member
					xt.GetMember (name);
				if (xm == null) {
					// still not? could it be omitted as content property or items ?
					if ((xm = GetExtraMember (xt)) != null) {
						// Note that this does not involve r.Read()
						foreach (var ni in ReadMember (xt, xm))
							yield return ni;
						yield break;
					}
				}
			}
			if (xm == null) {
				// Current element could be for another member in the parent type (if exists)
				if (parentType != null && parentType.GetMember (name) != null) {
					// stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
					yield return Node (XamlNodeType.None, null);
					yield break;
				}

				// ok, then create unknown member.
				xm = new XamlMember (name, xt, false); // FIXME: not sure if isAttachable is always false.
			}

			if (!r.IsEmptyElement) {
				r.Read ();
				foreach (var ni in ReadMember (xt, xm))
					yield return ni;
				r.MoveToContent ();
				r.ReadEndElement ();
			}
			else
				r.Read ();
		}
Example #30
0
		protected void Read_ListType (XamlReader r, bool isObjectReader)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");

			var defns = "clr-namespace:System.Collections.Generic;assembly=mscorlib";
			var defns2 = "clr-namespace:System;assembly=mscorlib";
			var defns3 = "clr-namespace:System.Xaml;assembly=System.Xaml";

			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "ns#1-3");
			Assert.AreEqual (defns, r.Namespace.Namespace, "ns#1-4");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("s", r.Namespace.Prefix, "ns#2-3-2");
			Assert.AreEqual (defns2, r.Namespace.Namespace, "ns#2-3-3");

			Assert.IsTrue (r.Read (), "ns#3-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#3-2");
			Assert.IsNotNull (r.Namespace, "ns#3-3");
			Assert.AreEqual ("sx", r.Namespace.Prefix, "ns#3-3-2");
			Assert.AreEqual (defns3, r.Namespace.Namespace, "ns#3-3-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (List<Type>), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
			Assert.IsTrue (xt.IsCollection, "#27");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("2", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"x:Int32", "Dictionary(s:Type, sx:XamlType)"};
			for (int i = 0; i < 2; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				// Here XamlObjectReader and XamlXmlReader significantly differs. (Lucky we can make this test conditional so simply)
				if (isObjectReader)
					Assert.AreEqual (XamlLanguage.PositionalParameters, r.Member, i + "#74-3");
				else
					Assert.AreEqual (XamlLanguage.Type.GetMember ("Type"), r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#75-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items
			
			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88");

			Assert.IsFalse (r.Read (), "#89");
		}