protected override void OnWriteEndMember ()
{
var xm = CurrentMember;
var state = object_states.Peek ();
if (xm == XamlLanguage.PositionalParameters) {
var l = (List<object>) state.Value;
state.Value = escaped_objects.Pop ();
state.IsInstantiated = true;
PopulateObject (true, l);
return;
} else if (xm == XamlLanguage.Arguments) {
if (state.FactoryMethod != null) {
var contents = (List<object>) state.Value;
var mi = state.Type.UnderlyingType.GetMethods (static_flags).FirstOrDefault (mii => mii.Name == state.FactoryMethod && mii.GetParameters ().Length == contents.Count);
if (mi == null)
throw new XamlObjectWriterException (String.Format ("Specified static factory method '{0}' for type '{1}' was not found", state.FactoryMethod, state.Type));
state.Value = mi.Invoke (null, contents.ToArray ());
}
else
PopulateObject (false, (List<object>) state.Value);
state.IsInstantiated = true;
escaped_objects.Pop ();
} else if (xm == XamlLanguage.Initialization) {
// ... and no need to do anything. The object value to pop *is* the return value.
} else if (xm == XamlLanguage.Name || xm == state.Type.GetAliasedProperty (XamlLanguage.Name)) {
string name = (string) CurrentMemberState.Value;
name_scope.RegisterName (name, state.Value);
} else {
if (xm.IsEvent)
SetEvent (xm, (string) CurrentMemberState.Value);
else if (!xm.IsReadOnly) // exclude read-only object such as collection item.
SetValue (xm, CurrentMemberState.Value);
}
}