public virtual object Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     if (declaration == null)
     {
         throw new ArgumentNullException("declaration");
     }
     object obj2 = null;
     using (CodeDomSerializerBase.TraceScope("TypeCodeDomSerializer::Deserialize"))
     {
         bool caseInsensitive = false;
         CodeDomProvider service = manager.GetService(typeof(CodeDomProvider)) as CodeDomProvider;
         if (service != null)
         {
             caseInsensitive = (service.LanguageOptions & LanguageOptions.CaseInsensitive) != LanguageOptions.None;
         }
         Type type = null;
         string name = declaration.Name;
         foreach (CodeTypeReference reference in declaration.BaseTypes)
         {
             Type type2 = manager.GetType(CodeDomSerializerBase.GetTypeNameFromCodeTypeReference(manager, reference));
             name = reference.BaseType;
             if ((type2 != null) && !type2.IsInterface)
             {
                 type = type2;
                 break;
             }
         }
         if (type == null)
         {
             CodeDomSerializerBase.Error(manager, System.Design.SR.GetString("SerializerTypeNotFound", new object[] { name }), "SerializerTypeNotFound");
         }
         if (CodeDomSerializerBase.GetReflectionTypeFromTypeHelper(manager, type).IsAbstract)
         {
             CodeDomSerializerBase.Error(manager, System.Design.SR.GetString("SerializerTypeAbstract", new object[] { type.FullName }), "SerializerTypeAbstract");
         }
         ResolveNameEventHandler handler = new ResolveNameEventHandler(this.OnResolveName);
         manager.ResolveName += handler;
         obj2 = manager.CreateInstance(type, null, declaration.Name, true);
         int count = declaration.Members.Count;
         this._nameTable = new HybridDictionary(count, caseInsensitive);
         this._statementTable = new Dictionary<string, CodeDomSerializerBase.OrderedCodeStatementCollection>(count);
         Dictionary<string, string> names = new Dictionary<string, string>(count);
         RootContext context = new RootContext(new CodeThisReferenceExpression(), obj2);
         manager.Context.Push(context);
         try
         {
             StringComparison comparisonType = caseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
             foreach (CodeTypeMember member in declaration.Members)
             {
                 CodeMemberField field = member as CodeMemberField;
                 if ((field != null) && !string.Equals(field.Name, declaration.Name, comparisonType))
                 {
                     this._nameTable[field.Name] = field;
                     if ((field.Type != null) && !string.IsNullOrEmpty(field.Type.BaseType))
                     {
                         names[field.Name] = CodeDomSerializerBase.GetTypeNameFromCodeTypeReference(manager, field.Type);
                     }
                 }
             }
             CodeMemberMethod[] initializeMethods = this.GetInitializeMethods(manager, declaration);
             if (initializeMethods == null)
             {
                 throw new InvalidOperationException();
             }
             foreach (CodeMemberMethod method in initializeMethods)
             {
                 foreach (CodeStatement statement in method.Statements)
                 {
                     CodeVariableDeclarationStatement statement2 = statement as CodeVariableDeclarationStatement;
                     if (statement2 != null)
                     {
                         this._nameTable[statement2.Name] = statement;
                     }
                 }
             }
             this._nameTable[declaration.Name] = context.Expression;
             foreach (CodeMemberMethod method2 in initializeMethods)
             {
                 CodeDomSerializerBase.FillStatementTable(manager, this._statementTable, names, method2.Statements, declaration.Name);
             }
             PropertyDescriptor descriptor = manager.Properties["SupportsStatementGeneration"];
             if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool) descriptor.GetValue(manager)))
             {
                 foreach (string str2 in this._nameTable.Keys)
                 {
                     if (str2.Equals(declaration.Name) || !this._statementTable.ContainsKey(str2))
                     {
                         continue;
                     }
                     CodeStatementCollection statements = this._statementTable[str2];
                     bool flag2 = false;
                     foreach (CodeStatement statement3 in statements)
                     {
                         object obj3 = statement3.UserData["GeneratedStatement"];
                         if (((obj3 == null) || !(obj3 is bool)) || !((bool) obj3))
                         {
                             flag2 = true;
                             break;
                         }
                     }
                     if (!flag2)
                     {
                         this._statementTable.Remove(str2);
                     }
                 }
             }
             base.DeserializePropertiesFromResources(manager, obj2, _designTimeFilter);
             CodeDomSerializerBase.OrderedCodeStatementCollection[] array = new CodeDomSerializerBase.OrderedCodeStatementCollection[this._statementTable.Count];
             this._statementTable.Values.CopyTo(array, 0);
             Array.Sort(array, StatementOrderComparer.Default);
             CodeDomSerializerBase.OrderedCodeStatementCollection statements2 = null;
             foreach (CodeDomSerializerBase.OrderedCodeStatementCollection statements3 in array)
             {
                 if (statements3.Name.Equals(declaration.Name))
                 {
                     statements2 = statements3;
                 }
                 else
                 {
                     this.DeserializeName(manager, statements3.Name, statements3);
                 }
             }
             if (statements2 != null)
             {
                 this.DeserializeName(manager, statements2.Name, statements2);
             }
         }
         finally
         {
             this._nameTable = null;
             this._statementTable = null;
             manager.ResolveName -= handler;
             manager.Context.Pop();
         }
     }
     return obj2;
 }
 private void AddStatement(string name, CodeStatement statement)
 {
     CodeDomSerializerBase.OrderedCodeStatementCollection statements = (CodeDomSerializerBase.OrderedCodeStatementCollection) this.statementTable[name];
     if (statements == null)
     {
         statements = new CodeDomSerializerBase.OrderedCodeStatementCollection {
             Order = this.statementTable.Count,
             Name = name
         };
         this.statementTable[name] = statements;
     }
     statements.Add(statement);
 }