예제 #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);
        }
예제 #2
0
 // <summary>
 // Serializes this object into a simple string (AppDomains like strings).
 //
 // Format: PropertyName,SubPropertiesExpanded;NextPropertyName,SubPropertiesExpanded;...
 // Where bools are recorded as 0 = false and 1 = true
 // </summary>
 // <returns>Serialized version of this state object (may be null)</returns>
 protected override string SerializeCore()
 {
     return(string.Concat(
                PersistedStateUtilities.Escape(_propertyName),
                ',',
                PersistedStateUtilities.BoolToDigit(_subPropertiesExpanded)));
 }
        // <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);
        }
 // <summary>
 // Serializes this object into a simple string (AppDomains like strings).
 //
 // Format: CategoryName,CategoryExpanded,AdvancedExpanded;NextCategoryName,CategoryExpanded,AdvancedExpanded;...
 // Where bools are recorded as 0 = false and 1 = true and ';' and ',' are escaped
 // </summary>
 // <returns>Serialized version of this state object (may be null)</returns>
 protected override string SerializeCore()
 {
     return(string.Concat(
                PersistedStateUtilities.Escape(_categoryName),
                ',',
                PersistedStateUtilities.BoolToDigit(_categoryExpanded),
                ',',
                PersistedStateUtilities.BoolToDigit(_advancedSectionExpanded)));
 }
        // IStateContainer Members

        // <summary>
        // Retrieves all stored IPropertyViewManager types under all persistence IDs
        // </summary>
        // <returns>All stored IPropertyViewManager types under all persistence IDs</returns>
        public object RetrieveState()
        {
            if (_persistenceIdToManagerTypeNameMap == null || _persistenceIdToManagerTypeNameMap.Count == 0)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> pair in _persistenceIdToManagerTypeNameMap)
            {
                if (sb.Length > 0)
                {
                    sb.Append(';');
                }

                sb.Append(PersistedStateUtilities.Escape(pair.Key));
                sb.Append(';');
                sb.Append(pair.Value);
            }

            return(sb.ToString());
        }