コード例 #1
0
        public override void ConvertToSurrogate(ImmutableSortedDictionary <TKey, TValue> value, ref ImmutableSortedDictionarySurrogate <TKey, TValue> surrogate)
        {
            if (value is null)
            {
                surrogate = default;
                return;
            }
            else
            {
                surrogate = new ImmutableSortedDictionarySurrogate <TKey, TValue>
                {
                    Values = new List <KeyValuePair <TKey, TValue> >(value)
                };

                if (!ReferenceEquals(value.KeyComparer, Comparer <TKey> .Default))
                {
                    surrogate.KeyComparer = value.KeyComparer;
                }

                if (!ReferenceEquals(value.ValueComparer, EqualityComparer <TKey> .Default))
                {
                    surrogate.ValueComparer = value.ValueComparer;
                }
            }
        }
コード例 #2
0
        public override ImmutableSortedDictionary <TKey, TValue> ConvertFromSurrogate(ref ImmutableSortedDictionarySurrogate <TKey, TValue> surrogate)
        {
            if (surrogate.Values is null)
            {
                return(null);
            }
            else
            {
                var result = ImmutableSortedDictionary.CreateRange(surrogate.Values);

                if (surrogate.KeyComparer is object && surrogate.ValueComparer is object)
                {
                    result = result.WithComparers(surrogate.KeyComparer, surrogate.ValueComparer);
                }
                else if (surrogate.KeyComparer is object)
                {
                    result = result.WithComparers(surrogate.KeyComparer);
                }

                return(result);
            }
        }