序列化避免异常的一种解决思路

 SerializationInfoEnumerator enumerator = info.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (enumerator.Value != null)
                {
                    if (enumerator.Name == "Caption")
                    {
                        this.caption = Convert.ToString(enumerator.Value);
                    }
                    else if (enumerator.Name == "Mark")
                    {
                        this.mark = Convert.ToString(enumerator.Value);
                    }
                    else if (enumerator.Name == "ImageIndex")
                    {
                        this.imageIndex = Convert.ToInt32(enumerator.Value);
                    }
                    else if (enumerator.Name == "ChildMenus")
                    {
                        this.childMenus = enumerator.Value as List<ToolMenu>;
                    }
                    else if (enumerator.Name == "DisplayStyle")
                    {
                        this.displayStyle = (MenuDisplayStyle)enumerator.Value;
                    }
                    else if (enumerator.Name == "GUID")
                    {
                        this.guid = Convert.ToString(enumerator.Value);
                    }
                    else if (enumerator.Name == "ISchecked")
                    {
                        this.isChecked = Convert.ToBoolean(enumerator.Value);
                    }
                    else if (enumerator.Name == "ISAllowCheck")
                    {
                        this.isAllowCheck = Convert.ToBoolean(enumerator.Value);
                    }
                    else if (enumerator.Name == "ISAllowDropIn")
                    {
                        this.isAllowDropIn = Convert.ToBoolean(enumerator.Value);
                    }
                    else if (enumerator.Name == "ISAllowDropOut")
                    {
                        this.isAllowDropOut = Convert.ToBoolean(enumerator.Value);
                    }
                    else if (enumerator.Name == "Alignment")
                    {
                        this.alignment = (MenuAlignment)enumerator.Value;
                    }
                    else if (enumerator.Name == "MenuType")
                    {
                        this.menuType = (MenuType)enumerator.Value;
                    }
                }
            }

 

posted @ 2015-08-12 21:04  洛晨随风  阅读(408)  评论(0编辑  收藏  举报