private static void WriteValue(Xaml.XamlReader xamlReader, XamlObjectWriter xamlWriter, XamlContextStack <WpfXamlFrame> stack, IStyleConnector styleConnector)
        {
            if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlLanguage.Shared)
            {
                bool isShared;
                if (bool.TryParse(xamlReader.Value as string, out isShared))
                {
                    if (!isShared)
                    {
                        if (!(xamlReader is Baml2006Reader))
                        {
                            throw new XamlParseException(SR.Get(SRID.SharedAttributeInLooseXaml));
                        }
                    }
                }
            }
            // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown
            if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlReaderHelper.Freeze)
            {
                bool freeze = Convert.ToBoolean(xamlReader.Value, TypeConverterHelper.InvariantEnglishUS);
                stack.CurrentFrame.FreezeFreezable = freeze;
                var bamlReader = xamlReader as System.Windows.Baml2006.Baml2006Reader;
                if (bamlReader != null)
                {
                    bamlReader.FreezeFreezables = freeze;
                }
            }
            // The space directive node stream should not be written because it induces object instantiation,
            // and the Baml2006Reader can produce space directives prematurely.
            else if (stack.CurrentFrame.Property == XmlSpace.Value || stack.CurrentFrame.Property == XamlLanguage.Space)
            {
                if (typeof(DependencyObject).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType))
                {
                    System.Diagnostics.Debug.Assert(xamlReader.Value is string, "XmlAttributeProperties.XmlSpaceProperty has the type string.");
                    stack.CurrentFrame.XmlSpace = (string)xamlReader.Value == "default";
                }
            }
            else
            {
                // Ideally we should check if we're inside FrameworkTemplate's Content and not register those.
                // However, checking if the instance is null accomplishes the same with a much smaller perf impact.
                if (styleConnector != null &&
                    stack.CurrentFrame.Instance != null &&
                    stack.CurrentFrame.Property == XamlLanguage.ConnectionId &&
                    typeof(Style).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType))
                {
                    styleConnector.Connect((int)xamlReader.Value, stack.CurrentFrame.Instance);
                }

                xamlWriter.WriteNode(xamlReader);
            }
        }
 private static void WriteStartObject(Xaml.XamlReader xamlReader, XamlObjectWriter xamlWriter, XamlContextStack <WpfXamlFrame> stack)
 {
     xamlWriter.WriteNode(xamlReader);
     // If there's a frame but no Type, that means there
     // was a namespace. Just set the Type
     if (stack.Depth != 0 && stack.CurrentFrame.Type == null)
     {
         stack.CurrentFrame.Type = xamlReader.Type;
     }
     else
     {
         // Propagate the FreezeFreezable property from the current stack frame
         stack.PushScope();
         stack.CurrentFrame.Type = xamlReader.Type;
         if (stack.PreviousFrame.FreezeFreezable)
         {
             stack.CurrentFrame.FreezeFreezable = true;
         }
     }
 }