コード例 #1
0
ファイル: ColorSetManager.cs プロジェクト: olesar/Altaxo
        public NamedColor GetDeserializedColorFromLevelAndSetName(Altaxo.Serialization.Xml.IXmlDeserializationInfo deserializationInfo, AxoColor colorValue, string colorName, string colorSetName)
        {
            // first have a look in the rename dictionary - maybe our color set has been renamed during deserialization
            var renameDictionary = deserializationInfo?.GetPropertyOrDefault <Dictionary <string, string> >(DeserializationRenameDictionaryKey);

            if (null != renameDictionary && renameDictionary.ContainsKey(colorSetName))
            {
                colorSetName = renameDictionary[colorSetName];
            }

            if (_allLists.TryGetValue(colorSetName, out var foundSet))                                               // if a set with the give name and level was found
            {
                if (foundSet.List.TryGetValue(colorName, out var foundColor) && colorValue.Equals(foundColor.Color)) // if the color is known by this name, and the color value matches
                {
                    return(foundColor);                                                                              // then return this found color
                }
                if (foundSet.List.TryGetValue(colorValue, out foundColor))                                           // if only the color value matches,
                {
                    return(foundColor);                                                                              // then return the found color, even if it has another name than the deserialized color
                }
                // set was found, but color is not therein -> return a color without set (or use the first set where the color could be found
                TryFindColorSetContaining(colorValue, colorName, out var cset);
                var result = new NamedColor(colorValue, colorName, cset);
                return(result);
            }
            else // the color set with the given name was not found by name
            {
                TryFindColorSetContaining(colorValue, colorName, out var cset);
                var result = new NamedColor(colorValue, colorName, cset);
                return(result);
            }
        }
コード例 #2
0
        /// <summary>
        /// Try to register the provided list. This function is intended to be used during deserialization. It keeps track of when a list was renamed, and stores
        /// this information in the deserialization info to be used by the members of the list during deserialization.
        /// </summary>
        /// <param name="deserializationInfo">The deserialization info of the deserialization that is under way. Can be null.</param>
        /// <param name="instance">The new list which is tried to register.</param>
        /// <param name="level">The level on which this list is defined.</param>
        /// <param name="storedList">On return, this is the list which is either registered, or is an already registed list with exactly the same elements.</param>
        /// <returns>True if the list was new and thus was added to the collection; false if the list has already existed.</returns>
        public bool TryRegisterList(Altaxo.Serialization.Xml.IXmlDeserializationInfo deserializationInfo, TList instance, Main.ItemDefinitionLevel level, out TList storedList)
        {
            var result = InternalTryRegisterList(instance, level, out storedList, true);

            var renameDictionary = deserializationInfo?.GetPropertyOrDefault <Dictionary <string, string> >(DeserializationRenameDictionaryKey);

            if (null != renameDictionary)
            {
                renameDictionary[instance.Name] = storedList.Name;
            }

            return(result);
        }