public virtual CodeTypeDeclaration Serialize (IDesignerSerializationManager manager, object root, ICollection members)
		{
			if (root == null)
				throw new ArgumentNullException ("root");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			RootContext rootContext = new RootContext (new CodeThisReferenceExpression (), root);
			StatementContext statementContext = new StatementContext ();
			if (members != null)
				statementContext.StatementCollection.Populate (members);
			statementContext.StatementCollection.Populate (root);
			CodeTypeDeclaration declaration = new CodeTypeDeclaration (manager.GetName (root));

			manager.Context.Push (rootContext);
			manager.Context.Push (statementContext);
			manager.Context.Push (declaration);

			if (members != null) {
				foreach (object member in members)
					base.SerializeToExpression (manager, member);
			}
			base.SerializeToExpression (manager, root);

			manager.Context.Pop ();
			manager.Context.Pop ();
			manager.Context.Pop ();

			return declaration;
		}
 private void IntegrateStatements(IDesignerSerializationManager manager, object root, ICollection members, StatementContext statementCxt, CodeTypeDeclaration typeDecl)
 {
     Dictionary<string, int> dictionary = new Dictionary<string, int>();
     List<CodeMethodMap> list = new List<CodeMethodMap>();
     if (members != null)
     {
         foreach (object obj2 in members)
         {
             if (obj2 != root)
             {
                 CodeStatementCollection statements = statementCxt.StatementCollection[obj2];
                 if (statements != null)
                 {
                     CodeMethodMap map;
                     int num;
                     CodeMemberMethod method = this.GetInitializeMethod(manager, typeDecl, obj2);
                     if (method == null)
                     {
                         throw new InvalidOperationException();
                     }
                     if (dictionary.TryGetValue(method.Name, out num))
                     {
                         map = list[num];
                     }
                     else
                     {
                         map = new CodeMethodMap(method);
                         list.Add(map);
                         dictionary[method.Name] = list.Count - 1;
                     }
                     if (statements.Count > 0)
                     {
                         map.Add(statements);
                     }
                 }
             }
         }
     }
     CodeStatementCollection statements2 = statementCxt.StatementCollection[root];
     if (statements2 != null)
     {
         CodeMethodMap map2;
         int num2;
         CodeMemberMethod method2 = this.GetInitializeMethod(manager, typeDecl, root);
         if (method2 == null)
         {
             throw new InvalidOperationException();
         }
         if (dictionary.TryGetValue(method2.Name, out num2))
         {
             map2 = list[num2];
         }
         else
         {
             map2 = new CodeMethodMap(method2);
             list.Add(map2);
             dictionary[method2.Name] = list.Count - 1;
         }
         if (statements2.Count > 0)
         {
             map2.Add(statements2);
         }
     }
     foreach (CodeMethodMap map3 in list)
     {
         map3.Combine();
         typeDecl.Members.Add(map3.Method);
     }
 }
 public virtual CodeTypeDeclaration Serialize(IDesignerSerializationManager manager, object root, ICollection members)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     CodeTypeDeclaration declaration = new CodeTypeDeclaration(manager.GetName(root));
     CodeThisReferenceExpression expression = new CodeThisReferenceExpression();
     RootContext context = new RootContext(expression, root);
     StatementContext context2 = new StatementContext();
     context2.StatementCollection.Populate(root);
     if (members != null)
     {
         context2.StatementCollection.Populate(members);
     }
     declaration.BaseTypes.Add(root.GetType());
     manager.Context.Push(declaration);
     manager.Context.Push(context);
     manager.Context.Push(context2);
     try
     {
         if (members != null)
         {
             foreach (object obj2 in members)
             {
                 if (obj2 != root)
                 {
                     base.SerializeToExpression(manager, obj2);
                 }
             }
         }
         base.SerializeToExpression(manager, root);
         this.IntegrateStatements(manager, root, members, context2, declaration);
     }
     finally
     {
         manager.Context.Pop();
         manager.Context.Pop();
         manager.Context.Pop();
     }
     return declaration;
 }
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            if ((manager == null) || (value == null))
            {
                throw new ArgumentNullException((manager == null) ? "manager" : "value");
            }
            CodeTypeDeclaration declaration = new CodeTypeDeclaration(manager.GetName(value));
            RootContext         context     = new RootContext(new CodeThisReferenceExpression(), value);

            using (CodeDomSerializerBase.TraceScope("RootCodeDomSerializer::Serialize"))
            {
                declaration.BaseTypes.Add(value.GetType());
                this.containerRequired = false;
                manager.Context.Push(context);
                manager.Context.Push(this);
                manager.Context.Push(declaration);
                if (!(manager is DesignerSerializationManager))
                {
                    manager.AddSerializationProvider(new CodeDomSerializationProvider());
                }
                try
                {
                    if (value is IComponent)
                    {
                        ISite site = ((IComponent)value).Site;
                        if (site == null)
                        {
                            return(declaration);
                        }
                        ICollection      components = site.Container.Components;
                        StatementContext context2   = new StatementContext();
                        context2.StatementCollection.Populate(components);
                        manager.Context.Push(context2);
                        try
                        {
                            foreach (IComponent component in components)
                            {
                                if ((component != value) && !base.IsSerialized(manager, component))
                                {
                                    if (base.GetSerializer(manager, component) != null)
                                    {
                                        base.SerializeToExpression(manager, component);
                                    }
                                    else
                                    {
                                        manager.ReportError(System.Design.SR.GetString("SerializerNoSerializerForComponent", new object[] { component.GetType().FullName }));
                                    }
                                }
                            }
                            manager.Context.Push(value);
                            try
                            {
                                if ((base.GetSerializer(manager, value) != null) && !base.IsSerialized(manager, value))
                                {
                                    base.SerializeToExpression(manager, value);
                                }
                                else
                                {
                                    manager.ReportError(System.Design.SR.GetString("SerializerNoSerializerForComponent", new object[] { value.GetType().FullName }));
                                }
                            }
                            finally
                            {
                                manager.Context.Pop();
                            }
                        }
                        finally
                        {
                            manager.Context.Pop();
                        }
                        CodeMemberMethod method = new CodeMemberMethod {
                            Name       = this.InitMethodName,
                            Attributes = MemberAttributes.Private
                        };
                        declaration.Members.Add(method);
                        ArrayList elements = new ArrayList();
                        foreach (object obj2 in components)
                        {
                            if (obj2 != value)
                            {
                                elements.Add(context2.StatementCollection[obj2]);
                            }
                        }
                        if (context2.StatementCollection[value] != null)
                        {
                            elements.Add(context2.StatementCollection[value]);
                        }
                        if (this.ContainerRequired)
                        {
                            this.SerializeContainerDeclaration(manager, method.Statements);
                        }
                        this.SerializeElementsToStatements(elements, method.Statements);
                    }
                    return(declaration);
                }
                finally
                {
                    manager.Context.Pop();
                    manager.Context.Pop();
                    manager.Context.Pop();
                }
            }
            return(declaration);
        }
        private void IntegrateStatements(IDesignerSerializationManager manager, object root, ICollection members, StatementContext statementCxt, CodeTypeDeclaration typeDecl)
        {
            Dictionary <string, int> dictionary = new Dictionary <string, int>();
            List <CodeMethodMap>     list       = new List <CodeMethodMap>();

            if (members != null)
            {
                foreach (object obj2 in members)
                {
                    if (obj2 != root)
                    {
                        CodeStatementCollection statements = statementCxt.StatementCollection[obj2];
                        if (statements != null)
                        {
                            CodeMethodMap    map;
                            int              num;
                            CodeMemberMethod method = this.GetInitializeMethod(manager, typeDecl, obj2);
                            if (method == null)
                            {
                                throw new InvalidOperationException();
                            }
                            if (dictionary.TryGetValue(method.Name, out num))
                            {
                                map = list[num];
                            }
                            else
                            {
                                map = new CodeMethodMap(method);
                                list.Add(map);
                                dictionary[method.Name] = list.Count - 1;
                            }
                            if (statements.Count > 0)
                            {
                                map.Add(statements);
                            }
                        }
                    }
                }
            }
            CodeStatementCollection statements2 = statementCxt.StatementCollection[root];

            if (statements2 != null)
            {
                CodeMethodMap    map2;
                int              num2;
                CodeMemberMethod method2 = this.GetInitializeMethod(manager, typeDecl, root);
                if (method2 == null)
                {
                    throw new InvalidOperationException();
                }
                if (dictionary.TryGetValue(method2.Name, out num2))
                {
                    map2 = list[num2];
                }
                else
                {
                    map2 = new CodeMethodMap(method2);
                    list.Add(map2);
                    dictionary[method2.Name] = list.Count - 1;
                }
                if (statements2.Count > 0)
                {
                    map2.Add(statements2);
                }
            }
            foreach (CodeMethodMap map3 in list)
            {
                map3.Combine();
                typeDecl.Members.Add(map3.Method);
            }
        }
 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     if ((manager == null) || (value == null))
     {
         throw new ArgumentNullException((manager == null) ? "manager" : "value");
     }
     CodeTypeDeclaration declaration = new CodeTypeDeclaration(manager.GetName(value));
     RootContext context = new RootContext(new CodeThisReferenceExpression(), value);
     using (CodeDomSerializerBase.TraceScope("RootCodeDomSerializer::Serialize"))
     {
         declaration.BaseTypes.Add(value.GetType());
         this.containerRequired = false;
         manager.Context.Push(context);
         manager.Context.Push(this);
         manager.Context.Push(declaration);
         if (!(manager is DesignerSerializationManager))
         {
             manager.AddSerializationProvider(new CodeDomSerializationProvider());
         }
         try
         {
             if (value is IComponent)
             {
                 ISite site = ((IComponent) value).Site;
                 if (site == null)
                 {
                     return declaration;
                 }
                 ICollection components = site.Container.Components;
                 StatementContext context2 = new StatementContext();
                 context2.StatementCollection.Populate(components);
                 manager.Context.Push(context2);
                 try
                 {
                     foreach (IComponent component in components)
                     {
                         if ((component != value) && !base.IsSerialized(manager, component))
                         {
                             if (base.GetSerializer(manager, component) != null)
                             {
                                 base.SerializeToExpression(manager, component);
                             }
                             else
                             {
                                 manager.ReportError(System.Design.SR.GetString("SerializerNoSerializerForComponent", new object[] { component.GetType().FullName }));
                             }
                         }
                     }
                     manager.Context.Push(value);
                     try
                     {
                         if ((base.GetSerializer(manager, value) != null) && !base.IsSerialized(manager, value))
                         {
                             base.SerializeToExpression(manager, value);
                         }
                         else
                         {
                             manager.ReportError(System.Design.SR.GetString("SerializerNoSerializerForComponent", new object[] { value.GetType().FullName }));
                         }
                     }
                     finally
                     {
                         manager.Context.Pop();
                     }
                 }
                 finally
                 {
                     manager.Context.Pop();
                 }
                 CodeMemberMethod method = new CodeMemberMethod {
                     Name = this.InitMethodName,
                     Attributes = MemberAttributes.Private
                 };
                 declaration.Members.Add(method);
                 ArrayList elements = new ArrayList();
                 foreach (object obj2 in components)
                 {
                     if (obj2 != value)
                     {
                         elements.Add(context2.StatementCollection[obj2]);
                     }
                 }
                 if (context2.StatementCollection[value] != null)
                 {
                     elements.Add(context2.StatementCollection[value]);
                 }
                 if (this.ContainerRequired)
                 {
                     this.SerializeContainerDeclaration(manager, method.Statements);
                 }
                 this.SerializeElementsToStatements(elements, method.Statements);
             }
             return declaration;
         }
         finally
         {
             manager.Context.Pop();
             manager.Context.Pop();
             manager.Context.Pop();
         }
     }
     return declaration;
 }
 internal void Serialize(IDesignerSerializationManager manager, IDictionary objectData, IDictionary objectState, IList shimObjectNames)
 {
     IContainer container = manager.GetService(typeof(IContainer)) as IContainer;
     if (container != null)
     {
         this.SetupVariableReferences(manager, container, objectData, shimObjectNames);
     }
     StatementContext context = new StatementContext();
     context.StatementCollection.Populate(objectData.Keys);
     manager.Context.Push(context);
     try
     {
         foreach (CodeDomComponentSerializationService.CodeDomSerializationStore.ObjectData data in objectData.Values)
         {
             CodeDomSerializer serializer = (CodeDomSerializer) manager.GetSerializer(data.Value.GetType(), typeof(CodeDomSerializer));
             object[] objArray = new object[6];
             CodeStatementCollection statements = new CodeStatementCollection();
             manager.Context.Push(statements);
             if (serializer != null)
             {
                 if (data.EntireObject)
                 {
                     if (!base.IsSerialized(manager, data.Value))
                     {
                         if (data.Absolute)
                         {
                             objArray[0] = serializer.SerializeAbsolute(manager, data.Value);
                         }
                         else
                         {
                             objArray[0] = serializer.Serialize(manager, data.Value);
                         }
                         CodeStatementCollection statements2 = context.StatementCollection[data.Value];
                         if ((statements2 != null) && (statements2.Count > 0))
                         {
                             objArray[1] = statements2;
                         }
                         if (statements.Count > 0)
                         {
                             CodeStatementCollection statements3 = objArray[0] as CodeStatementCollection;
                             if (statements3 != null)
                             {
                                 statements3.AddRange(statements);
                             }
                         }
                     }
                     else
                     {
                         objArray[0] = context.StatementCollection[data.Value];
                     }
                 }
                 else
                 {
                     CodeStatementCollection statements4 = new CodeStatementCollection();
                     foreach (CodeDomComponentSerializationService.CodeDomSerializationStore.MemberData data2 in data.Members)
                     {
                         if (data2.Member.Attributes.Contains(DesignOnlyAttribute.Yes))
                         {
                             PropertyDescriptor member = data2.Member as PropertyDescriptor;
                             if ((member != null) && member.PropertyType.IsSerializable)
                             {
                                 if (objArray[3] == null)
                                 {
                                     objArray[3] = new Hashtable();
                                 }
                                 ((Hashtable) objArray[3])[member.Name] = member.GetValue(data.Value);
                             }
                         }
                         else if (data2.Absolute)
                         {
                             statements4.AddRange(serializer.SerializeMemberAbsolute(manager, data.Value, data2.Member));
                         }
                         else
                         {
                             statements4.AddRange(serializer.SerializeMember(manager, data.Value, data2.Member));
                         }
                     }
                     objArray[0] = statements4;
                 }
             }
             if (statements.Count > 0)
             {
                 CodeStatementCollection statements5 = objArray[0] as CodeStatementCollection;
                 if (statements5 != null)
                 {
                     statements5.AddRange(statements);
                 }
             }
             manager.Context.Pop();
             ArrayList list = null;
             List<string> list2 = null;
             IEventBindingService service = manager.GetService(typeof(IEventBindingService)) as IEventBindingService;
             if (data.EntireObject)
             {
                 foreach (PropertyDescriptor descriptor2 in TypeDescriptor.GetProperties(data.Value))
                 {
                     if ((!descriptor2.ShouldSerializeValue(data.Value) && !descriptor2.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden)) && (descriptor2.Attributes.Contains(DesignerSerializationVisibilityAttribute.Content) || !descriptor2.IsReadOnly))
                     {
                         if (list == null)
                         {
                             list = new ArrayList(data.Members.Count);
                         }
                         list.Add(descriptor2.Name);
                     }
                 }
                 if (service != null)
                 {
                     foreach (PropertyDescriptor descriptor3 in service.GetEventProperties(TypeDescriptor.GetEvents(data.Value)))
                     {
                         if (((descriptor3 != null) && !descriptor3.IsReadOnly) && (descriptor3.GetValue(data.Value) == null))
                         {
                             if (list2 == null)
                             {
                                 list2 = new List<string>();
                             }
                             list2.Add(descriptor3.Name);
                         }
                     }
                 }
             }
             else
             {
                 foreach (CodeDomComponentSerializationService.CodeDomSerializationStore.MemberData data3 in data.Members)
                 {
                     PropertyDescriptor property = data3.Member as PropertyDescriptor;
                     if ((property != null) && !property.ShouldSerializeValue(data.Value))
                     {
                         if ((service != null) && (service.GetEvent(property) != null))
                         {
                             if (list2 == null)
                             {
                                 list2 = new List<string>();
                             }
                             list2.Add(property.Name);
                         }
                         else
                         {
                             if (list == null)
                             {
                                 list = new ArrayList(data.Members.Count);
                             }
                             list.Add(property.Name);
                         }
                     }
                 }
             }
             PropertyDescriptor descriptor5 = TypeDescriptor.GetProperties(data.Value)["Modifiers"];
             if (descriptor5 != null)
             {
                 objArray[5] = descriptor5.GetValue(data.Value);
             }
             if (list != null)
             {
                 objArray[2] = (string[]) list.ToArray(typeof(string));
             }
             if (list2 != null)
             {
                 objArray[4] = list2;
             }
             if ((objArray[0] != null) || (objArray[2] != null))
             {
                 objectState[data.Name] = objArray;
             }
         }
     }
     finally
     {
         manager.Context.Pop();
     }
 }