Skip to content

Commit

Permalink
Support get-based property value (as omitted StartObject form) in Xam…
Browse files Browse the repository at this point in the history
…lXmlReader.

This is a bit complicated to determine, and the identified condition could
be wrong (so far no regression).

It may be now missing the point to use IsWritePublic in some area to identify
GetObject node from XML stream. (Future consideration.)

Fixed bug #682131.
  • Loading branch information
Atsushi Eno committed Mar 24, 2011
1 parent 75c1d16 commit be2b594
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 3 deletions.
19 changes: 16 additions & 3 deletions mcs/class/System.Xaml/System.Xaml/XamlXmlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ void ReadStartTypeOrContentGetObject ()
SetGetObject ();
return;
}

// 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
if (!get_flags.Peek () &&
!(current_member is XamlDirective) &&
!xt.IsMarkupExtension) {
SetGetObject ();
return;
}
}

types.Push (xt);
Expand Down Expand Up @@ -508,11 +521,11 @@ void ReadValue ()

void SetGetObject ()
{
current = null; // do not clear current_member as it is reused in the next Read().
node_type = XamlNodeType.GetObject;
inside_object_not_member = true;
types.Push (current_member.Type);
get_flags.Push (true);
current = current_member = null;
node_type = XamlNodeType.GetObject;
inside_object_not_member = true;
}

XamlDirective FindStandardDirective (string name, AllowedMemberLocations loc)
Expand Down
15 changes: 15 additions & 0 deletions mcs/class/System.Xaml/Test/System.Xaml/TestedTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,21 @@ public class NullableContainer
{
public int? TestProp { get; set; }
}

public class DirectListContainer // for such xml that directly contains items in <*.Items> element.
{
public IList<DirectListContent> Items { get; set; }

public DirectListContainer ()
{
this.Items = new List<DirectListContent> ();
}
}

public class DirectListContent
{
public string Value { get; set; }
}
}

namespace XamlTest
Expand Down
10 changes: 10 additions & 0 deletions mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,5 +1361,15 @@ public void Write_NullableContainer ()
Assert.AreEqual (5, res.TestProp, "#1");
}
}

[Test]
public void Write_DirectListContainer ()
{
using (var xr = GetReader ("DirectListContainer.xml")) {
var res = (DirectListContainer) XamlServices.Load (xr);
Assert.AreEqual (3, res.Items.Count, "#1");
Assert.AreEqual ("Hello3", res.Items [2].Value, "#2");
}
}
}
}
90 changes: 90 additions & 0 deletions mcs/class/System.Xaml/Test/System.Xaml/XamlReaderTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,96 @@ protected void Read_NullableContainer (XamlReader r)

Assert.IsFalse (r.Read (), "end");
}

protected void Read_DirectListContainer (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");

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#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: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");
}

protected void Read_AttachedProperty (XamlReader r)
{
Expand Down
8 changes: 8 additions & 0 deletions mcs/class/System.Xaml/Test/System.Xaml/XamlXmlReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,14 @@ public void Read_NullableContainer ()
Read_NullableContainer (r);
}

// It is not really a common test; it just makes use of base helper methods.
[Test]
public void Read_DirectListContainer ()
{
var r = GetReader ("DirectListContainer.xml");
Read_DirectListContainer (r);
}

#region non-common tests
[Test]
public void Bug680385 ()
Expand Down

0 comments on commit be2b594

Please sign in to comment.