// 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 #2
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");
		}
Example #3
0
 public XamlMember GetAttachableMember(XamlType xamlType, string name)
 {
     return xamlType.GetAttachableMember(name);
 }
Example #4
0
        // XamlDomObject.GetMemberNode() needs to take a XamlType and string for supporting unknown attached members.
        // This constructor is here to match that.
        public XamlDomMember(XamlType declaringType, string attachedMember, params XamlDomItem[] items)
        {
            if (declaringType == null)
            {
                throw new ArgumentNullException("declaringType");
            }
            if (attachedMember == null)
            {
                throw new ArgumentNullException("attachedMember");
            }

            foreach (var itemNode in items)
            {
                Items.Add(itemNode);
            }

            var member = declaringType.GetAttachableMember(attachedMember);
            if (member == null)
            {
                throw new NotImplementedException("Unknown members are not implemented");
            }

            _member = member;
            Resolve();
        }
 public XamlMember GetXamlAttachableProperty(XamlType xamlType, string propertyName)
 {
     if (xamlType.IsUnknown)
     {
         return null;
     }
     XamlMember attachableMember = xamlType.GetAttachableMember(propertyName);
     if (!this.IsVisible(attachableMember, null))
     {
         return null;
     }
     return attachableMember;
 }