public CodeDomSerializationProvider ()
		{
			_componentSerializer = new ComponentCodeDomSerializer ();
			_propertySerializer = new PropertyCodeDomSerializer ();
			_eventSerializer = new EventCodeDomSerializer ();
			_collectionSerializer = new CollectionCodeDomSerializer ();
			_primitiveSerializer = new PrimitiveCodeDomSerializer ();
			_rootSerializer = new RootCodeDomSerializer ();
			_enumSerializer = new EnumCodeDomSerializer ();
			_othersSerializer = new CodeDomSerializer ();
		}
 public CodeDomSerializationProvider()
 {
     _componentSerializer  = new ComponentCodeDomSerializer();
     _propertySerializer   = new PropertyCodeDomSerializer();
     _eventSerializer      = new EventCodeDomSerializer();
     _collectionSerializer = new CollectionCodeDomSerializer();
     _primitiveSerializer  = new PrimitiveCodeDomSerializer();
     _rootSerializer       = new RootCodeDomSerializer();
     _enumSerializer       = new EnumCodeDomSerializer();
     _othersSerializer     = new CodeDomSerializer();
 }
        /// <include file='doc\ComponentCodeDomSerializer.uex' path='docs/doc[@for="ComponentCodeDomSerializer.SerializeDeclaration"]/*' />
        /// <devdoc>
        ///     This ensures that the declaration for the component exists in the code class.  In
        ///     addition, it will wire up the creation of the object in the init method.
        /// </devdoc>
        private void SerializeDeclaration(IDesignerSerializationManager manager, CodeStatementCollection statements, object value)
        {
            Debug.WriteLineIf(traceSerialization.TraceVerbose, "ComponentCodeDomSerializer::SerializeDeclaration");
            Debug.Indent();

            // Attempt to get the type declaration in the context.
            //
            CodeTypeDeclaration docType = (CodeTypeDeclaration)manager.Context[typeof(CodeTypeDeclaration)];
            string name = manager.GetName(value);

            Debug.Assert(name != null, "Cannot serialize declaration of unnamed component.");

            if (name != null)
            {
                CodeTypeReference type = new CodeTypeReference(value.GetType());

                // Add the declaration to the code type, if we found one.
                //
                if (docType != null)
                {
                    MemberAttributes   modifiers    = MemberAttributes.Private;
                    PropertyDescriptor modifierProp = TypeDescriptor.GetProperties(value)["Modifiers"];
                    if (modifierProp != null && modifierProp.PropertyType == typeof(MemberAttributes))
                    {
                        modifiers = (MemberAttributes)modifierProp.GetValue(value);
                    }
                    else
                    {
                        Debug.WriteLineIf(traceSerialization.TraceWarning, "WARNING: No Modifiers property on component " + name + "; assuming private.");
                    }

                    // Create a field on the class that represents this component.
                    //
                    CodeMemberField field = new CodeMemberField(type, name);
                    field.Attributes = modifiers;

                    docType.Members.Add(field);
                }

                // Next, add the instance creation to our statement list.  We check to see if there is an instance
                // descriptor attached to this compnent type that knows how to emit, which allows components to
                // init themselves from static method calls or public static fields, rather than always creating
                // an instance.
                //
                CodeFieldReferenceExpression fieldRef = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), name);
                CodeExpression createExpression       = null;

                if (TypeDescriptor.GetConverter(value).CanConvertTo(typeof(InstanceDescriptor)))
                {
                    // Got an instance descriptor.  Ask it to serialize
                    //
                    object o = InstanceDescriptorCodeDomSerializer.Default.Serialize(manager, value);
                    if (o is CodeExpression)
                    {
                        createExpression = (CodeExpression)o;
                    }
                }

                if (createExpression == null)
                {
                    // Standard object create
                    //
                    CodeObjectCreateExpression objectCreate = new CodeObjectCreateExpression();
                    objectCreate.CreateType = type;

                    // Check to see if this component has a constructor that takes an IContainer.  If it does,
                    // then add the container reference to the creation parameters.
                    //
                    ConstructorInfo ctr = value.GetType().GetConstructor(BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                                                         null, containerConstructor, null);

                    if (ctr != null)
                    {
                        Debug.WriteLineIf(traceSerialization.TraceVerbose, "Object requires an IContainer constructor.");
                        RootCodeDomSerializer rootSerializer = (RootCodeDomSerializer)manager.Context[typeof(RootCodeDomSerializer)];
                        Debug.WriteLineIf(traceSerialization.TraceWarning && rootSerializer == null, "WARNING : Context stack does not have a root serializer on it so we cannot emit a required container constructor.");
                        if (rootSerializer != null)
                        {
                            CodeFieldReferenceExpression container = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), rootSerializer.ContainerName);
                            objectCreate.Parameters.Add(container);
                            rootSerializer.ContainerRequired = true;
                        }
                    }

                    createExpression = objectCreate;
                }


                statements.Add(new CodeAssignStatement(fieldRef, createExpression));
            }

            Debug.Unindent();
        }