예제 #1
0
        // <summary>
        // Attempts to deserialize a string into a PropertyState object
        // </summary>
        // <param name="propertyStateString">String to deserialize</param>
        // <returns>Instance of PropertyState if the serialized string was valid, null otherwise.</returns>
        public static PropertyState Deserialize(string propertyStateString)
        {
            string[] args = propertyStateString.Split(',');
            if (args == null || args.Length != 2)
            {
                return(null);
            }

            bool?subPropertiesExpanded = PersistedStateUtilities.DigitToBool(args[1]);

            if (subPropertiesExpanded == null)
            {
                return(null);
            }

            string propertyName = PersistedStateUtilities.Unescape(args[0]);

            if (string.IsNullOrEmpty(propertyName))
            {
                return(null);
            }

            PropertyState propertyState = new PropertyState(propertyName);

            propertyState.SubPropertiesExpanded = (bool)subPropertiesExpanded;
            return(propertyState);
        }
        // <summary>
        // Attempts to deserialize a string into a CategoryState object
        // </summary>
        // <param name="categoryStateString">String to deserialize</param>
        // <returns>Instance of CategoryState if the serialized string was valid, null otherwise.</returns>
        public static CategoryState Deserialize(string categoryStateString)
        {
            string[] args = categoryStateString.Split(',');
            if (args == null || args.Length != 3)
            {
                return(null);
            }

            bool?categoryExpanded        = PersistedStateUtilities.DigitToBool(args[1]);
            bool?advancedSectionExpanded = PersistedStateUtilities.DigitToBool(args[2]);

            if (categoryExpanded == null || advancedSectionExpanded == null)
            {
                return(null);
            }

            string categoryName = PersistedStateUtilities.Unescape(args[0]);

            if (string.IsNullOrEmpty(categoryName))
            {
                return(null);
            }

            CategoryState categoryState = new CategoryState(categoryName);

            categoryState.CategoryExpanded        = (bool)categoryExpanded;
            categoryState.AdvancedSectionExpanded = (bool)advancedSectionExpanded;
            return(categoryState);
        }