Fixed bug #693779.
throw new NotSupportedException (String.Format ("not supported operation on directive member {0}", member));
if (UnderlyingSetter == null)
throw new NotSupportedException (String.Format ("Attempt to set value from read-only property {0}", member));
- UnderlyingSetter.Invoke (instance, new object [] {value});
+ if (member.IsAttachable)
+ UnderlyingSetter.Invoke (null, new object [] {instance, value});
+ else
+ UnderlyingSetter.Invoke (instance, new object [] {value});
}
public virtual ShouldSerializeResult ShouldSerializeValue (object instance)
else if (member.IsDirective)
return;
else if (member.IsAttachable)
- AttachablePropertyServices.SetProperty (object_states.Peek ().Value, new AttachableMemberIdentifier (member.DeclaringType.UnderlyingType, member.Name), value);
+ member.Invoker.SetValue (object_states.Peek ().Value, value);
else if (!source.OnSetValue (this, member, value))
member.Invoker.SetValue (object_states.Peek ().Value, value);
}
{
}
+ public class Attached2
+ {
+ internal String Property { get; set; }
+ }
+
+ public class AttachedWrapper3
+ {
+ public static void SetProperty (Attached2 a, string value)
+ {
+ a.Property = value;
+ }
+ }
+
public class EventStore
{
public bool Method1Invoked;
xw.WriteEndObject ();
}
+ [Test]
+ public void WriteAttachableProperty ()
+ {
+ Attached2 result = null;
+
+ var rsettings = new XamlXmlReaderSettings ();
+ using (var reader = new XamlXmlReader (new StringReader (String.Format (@"<Attached2 AttachedWrapper3.Property=""Test"" xmlns=""clr-namespace:MonoTests.System.Xaml;assembly={0}""></Attached2>", typeof (AttachedWrapper3).Assembly.GetName ().Name)), rsettings)) {
+ var wsettings = new XamlObjectWriterSettings ();
+ using (var writer = new XamlObjectWriter (reader.SchemaContext, wsettings)) {
+ XamlServices.Transform (reader, writer, false);
+ result = (Attached2) writer.Result;
+ }
+ }
+
+ Assert.AreEqual ("Test", result.Property, "#1");
+ }
+
// extra use case based tests.
[Test]
Assert.IsTrue (x.IsEvent, "#6");
}
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void AttachablePropertySetValueNullObject ()
+ {
+ var xt = new XamlType (typeof (Attachable), sctx);
+ var apl = xt.GetAllAttachableMembers ();
+ var foo = apl.First (ap => ap.Name == "Foo");
+ Assert.IsTrue (foo.IsAttachable, "#7");
+ foo.Invoker.SetValue (null, "xxx");
+ }
+
+ [Test]
+ public void AttachablePropertySetValueSuccess ()
+ {
+ var xt = new XamlType (typeof (Attachable), sctx);
+ var apl = xt.GetAllAttachableMembers ();
+ var foo = apl.First (ap => ap.Name == "Foo");
+ Assert.IsTrue (foo.IsAttachable, "#7");
+ var obj = new object ();
+ foo.Invoker.SetValue (obj, "xxx"); // obj is non-null, so valid.
+ // FIXME: this line should be unnecessary.
+ AttachablePropertyServices.RemoveProperty (obj, new AttachableMemberIdentifier (foo.Type.UnderlyingType, foo.Name));
+ }
+
[Test]
public void ReadOnlyPropertyContainer ()
{