Assert.IsTrue (r.Read (), "#36");
Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#37");
// static Foo is not included in GetAllXembers() return value.
- // nonpublic Baz does not appear either.
+ // ReadOnly is not included in GetAllMembers() return value neither.
+ // nonpublic Baz is a member, but does not appear in the reader.
Assert.IsTrue (r.Read (), "#51");
Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#52");
var r = new XamlObjectReader (obj);
Read_ArrayOrArrayExtension (r, obj);
}
+
+ [Test]
+ public void Read_MyArrayExtension ()
+ {
+ var obj = new MyArrayExtension (new int [] {5, -3, 0});
+ var r = new XamlObjectReader (obj);
+ Read_ArrayOrArrayExtensionOrMyArrayExtension (r, obj, typeof (MyArrayExtension));
+ }
void Read_ArrayOrArrayExtension (XamlObjectReader r, object instance)
{
+ Read_ArrayOrArrayExtensionOrMyArrayExtension (r, instance, typeof (ArrayExtension));
+ }
+
+ void Read_ArrayOrArrayExtensionOrMyArrayExtension (XamlObjectReader r, object instance, 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.IsTrue (r.Read (), "#21");
Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
- var xt = new XamlType (typeof (ArrayExtension), r.SchemaContext);
+ var xt = new XamlType (extType, r.SchemaContext);
Assert.AreEqual (xt, r.Type, "#23");
Assert.AreEqual (instance, r.Instance, "#26"); // different between Array and ArrayExtension. Also, different from Type and TypeExtension (Type returns TypeExtension, while Array remains to return Array)
public static string Foo { get; set; }
public string Bar { get; set; }
public string Baz { internal get; set; }
+ public string ReadOnly {
+ get { return Foo; }
+ }
}
public class MyExtension : MarkupExtension
{
var xt = new XamlType (typeof (ComplexPositionalParameterWrapper), sctx);
}
+
+ [Test]
+ public void CustomArrayExtension ()
+ {
+ var xt = new XamlType (typeof (MyArrayExtension), sctx);
+ }
}
class MyXamlType : XamlType
{
public string Foo { get; set; }
}
+
+ //[MarkupExtensionReturnType (typeof (Array))]
+ //[ContentProperty ("Items")] ... so, these attributes do not affect XamlObjectReader.
+ public class MyArrayExtension : MarkupExtension
+ {
+ public MyArrayExtension ()
+ {
+ Items = new ArrayList ();
+ }
+
+ public MyArrayExtension (Array array)
+ {
+ this.Items = array;
+ this.Type = array.GetType ().GetElementType ();
+ }
+
+ public MyArrayExtension (Type type)
+ : this ()
+ {
+ this.Type = type;
+ }
+
+ [ConstructorArgument ("type")]
+ public Type Type { get; set; }
+
+ public IList Items { get; private set; }
+
+ public override object ProvideValue (IServiceProvider serviceProvider)
+ {
+ if (Type == null)
+ throw new InvalidOperationException ("Type property must be set before calling ProvideValue method");
+
+ Array a = Array.CreateInstance (Type, Items.Count);
+ Items.CopyTo (a, 0);
+ return a;
+ }
+ }
}