Part of fix #3033 - support ISupportInitialize and relevant XamlObjectWriterSettings...
authorAtsushi Eno <atsushi@ximian.com>
Fri, 9 Mar 2012 08:35:08 +0000 (17:35 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Fri, 9 Mar 2012 08:35:08 +0000 (17:35 +0900)
mcs/class/System.Xaml/System.Xaml/XamlObjectWriter.cs

index 6ef9ffa3f1976fbe6ddf54041bee6cc7abf67a66..76f67bc6f6a3ca4507785602e22ba81f5226ffaf 100644 (file)
@@ -24,6 +24,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Globalization;
 using System.Linq;
 using System.Reflection;
@@ -294,6 +295,8 @@ namespace System.Xaml
                        
                        if (state.Type.IsAmbient)
                                ambient_provider.Pop ();
+                       else
+                               HandleEndInit (obj);
                        
                        object_states.Push (state);
                        if (object_states.Count == 1) {
@@ -413,6 +416,7 @@ namespace System.Xaml
                        state.IsInstantiated = true;
                        if (state.Type.IsAmbient)
                                ambient_provider.Push (new AmbientPropertyValue (CurrentMember, state.Value));
+                       HandleBeginInit (state.Value);
                }
 
                protected override void OnWriteValue (object value)
@@ -570,6 +574,8 @@ namespace System.Xaml
                        state.IsInstantiated = true;
                        if (state.Type.IsAmbient)
                                ambient_provider.Push (new AmbientPropertyValue (CurrentMember, obj));
+                       else
+                               HandleBeginInit (obj);
                }
 
                internal IXamlNameResolver name_resolver {
@@ -594,5 +600,23 @@ namespace System.Xaml
                                }
                        }
                }
+               
+               void HandleBeginInit (object value)
+               {
+                       var si = value as ISupportInitialize;
+                       if (si == null)
+                               return;
+                       si.BeginInit ();
+                       source.OnAfterBeginInit (value);
+               }
+               
+               void HandleEndInit (object value)
+               {
+                       var si = value as ISupportInitialize;
+                       if (si == null)
+                               return;
+                       si.EndInit ();
+                       source.OnAfterEndInit (value);
+               }
        }
 }