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

时间:2021-04-25 20:12:47
 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;
                    }
                }
            }