public static bool IsSet(this IEnumerable <string>? @this, IEnumerable <string>?items, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.IsSet(items, comparison.ToStringComparer());
 public static HashSet <string> Without(this IEnumerable <string>? @this, IEnumerable <string>?items, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.Without(items, comparison.ToStringComparer());
 public static bool Has([NotNullWhen(true)] this IEnumerable <string>? @this, IEnumerable <string>?values, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.Has(values, comparison.ToStringComparer());
 public static ImmutableSortedSet <string> ToImmutableSortedSet(this IEnumerable <string>? @this, StringComparison comparison = StringComparison.Ordinal)
 => @this?.ToImmutableSortedSet(comparison.ToStringComparer()) ?? ImmutableSortedSet.Create <string>(comparison.ToStringComparer());
 public static IEnumerable <int> ToIndex(this IEnumerable <string>? @this, string value, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.ToIndex(value, comparison.ToStringComparer());
 public static IDictionary <string, IEnumerable <V> > Group <V>(this IEnumerable <V>? @this, Func <V, string> keyFactory, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.Group(keyFactory, comparison.ToStringComparer());
 public static ImmutableSortedDictionary <string, V> ToImmutableSortedDictionary <V>(
     this IEnumerable <KeyValuePair <string, V> >? @this
     , StringComparison keyComparison      = StringComparison.Ordinal
     , IEqualityComparer <V>?valueComparer = null)
 => @this?.ToImmutableSortedDictionary(keyComparison.ToStringComparer(), valueComparer) ?? ImmutableSortedDictionary.Create <string, V>(keyComparison.ToStringComparer(), valueComparer);
 public static ImmutableDictionary <string, V> ToImmutableDictionary <V>(
     this IEnumerable <KeyValuePair <string, V> >? @this
     , StringComparison keyComparison = StringComparison.OrdinalIgnoreCase)
 => @this?.ToImmutableDictionary(keyComparison.ToStringComparer()) ?? ImmutableDictionary.Create <string, V>(keyComparison.ToStringComparer());
 public static ImmutableDictionary <string, V> ToImmutableDictionary <T, V>(
     this IEnumerable <T>? @this
     , Func <T, string> keyFactory
     , Func <T, V> valueFactory
     , StringComparison keyComparison = StringComparison.OrdinalIgnoreCase)
 => @this?.ToImmutableDictionary(keyFactory, valueFactory, keyComparison.ToStringComparer()) ?? ImmutableDictionary.Create <string, V>(keyComparison.ToStringComparer());
 public static HashSet <string> ToHashSet(this IEnumerable <string>? @this, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.ToHashSet(comparison.ToStringComparer());
 public static Dictionary <string, V> ToDictionary <T, V>(this IEnumerable <T>? @this, Func <T, string> keyFactory, Func <T, V> valueFactory, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.ToDictionary(keyFactory, valueFactory, comparison.ToStringComparer());
 public static Dictionary <string, V> ToDictionary <V>(this IEnumerable <ValueTuple <string, V> >? @this, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => @this.ToDictionary(comparison.ToStringComparer());
Exemple #13
0
        private void SerializeTo(IDictionary <string, string> source, XmlDocument doc)
        {
            XmlNode xnRoot = null;

            if (!doc.HasChildNodes)
            {
                doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty));
                xnRoot = doc.CreateElement(RootNodeName);
                doc.AppendChild(xnRoot);
            }
            else
            {
                foreach (XmlNode xn in doc.ChildNodes)
                {
                    if (xn.Name.Equals(RootNodeName, StringComparison))
                    {
                        xnRoot = xn;
                        break;
                    }
                }

                if (xnRoot == null)
                {
                    xnRoot = doc.CreateElement(RootNodeName);
                    doc.AppendChild(xnRoot);
                }
            }

            //We store the existing nodes for future use.
            var existingNodes = new Dictionary <string, XmlNode>();

            if (xnRoot.HasChildNodes)
            {
                foreach (XmlNode xn in xnRoot.ChildNodes)
                {
                    var key        = string.Empty;
                    var attributes = xn.Attributes;
                    if ((attributes == null) || (attributes.Count == 0))
                    {
                        continue;
                    }

                    foreach (XmlAttribute xa in xn.Attributes)
                    {
                        if (AllowedKeyAttributeNames.Contains(xa.Name, StringComparison.ToStringComparer()))
                        {
                            key = xa.Value;
                            break;
                        }
                    }

                    if (!existingNodes.ContainsKey(key) && !string.IsNullOrEmpty(key))
                    {
                        existingNodes.Add(key, xn);
                    }
                }
            }

            foreach (string key in source.Keys)
            {
                if (existingNodes.ContainsKey(key))
                {
                    var          xn      = existingNodes[key];
                    XmlAttribute xaValue = null;
                    foreach (XmlAttribute xa in xn.Attributes)
                    {
                        if (AllowedValueAttributeNames.Contains(xa.Name, StringComparison.ToStringComparer()))
                        {
                            xaValue = xa;
                        }
                    }

                    if (xaValue == null)
                    {
                        xaValue = doc.CreateAttribute(DefaultValueAttributeName);
                        xn.Attributes.Append(xaValue);
                    }

                    xaValue.Value = source[key];
                }
                else
                {
                    XmlElement   item    = doc.CreateElement(ItemNodeName);
                    XmlAttribute xaKey   = doc.CreateAttribute(DefaultKeyAttributeName);
                    XmlAttribute xaValue = doc.CreateAttribute(DefaultValueAttributeName);

                    xaKey.Value   = key;
                    xaValue.Value = source[key];

                    item.Attributes.Append(xaKey);
                    item.Attributes.Append(xaValue);

                    xnRoot.AppendChild(item);
                }
            }
        }
 public static bool Is([NotNullWhen(true)] this string? @this, string?value, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
 => comparison.ToStringComparer().Equals(@this, value);