示例#1
0
        public static void AddIfNotContains <T>(this ICollection <T> source, IEnumerable <T> items)
        {
            source.CheckNotNull(nameof(source));
            items.CheckNotNull(nameof(source));

            foreach (var item in items)
            {
                source.AddIfNotContains(item);
            }
        }
示例#2
0
 /// <summary>
 ///     如果不包含,则添加
 /// </summary>
 /// <param name="this"></param>
 /// <param name="items">匹配项集合</param>
 /// <typeparam name="T">集合中元素的类型</typeparam>
 /// <exception cref="NotSupportedException"> <paramref name="this" /> maybe is read-only</exception>
 /// <example>
 ///     <code>
 ///         <![CDATA[
 /// var list = new List<string> {"aa", "bb"};
 /// var appendList = new[] {"cc", "aa"};
 /// list.AddIfNotContains(appendList);
 /// // {"aa", "bb", "cc"}
 ///         ]]>
 ///     </code>
 /// </example>
 public static void AddIfNotContains <T>(this ICollection <T> @this, IEnumerable <T> items)
 {
     if (@this == null || items == null)
     {
         return;
     }
     foreach (var item in items)
     {
         @this.AddIfNotContains(item);
     }
 }
示例#3
0
 /// <summary>
 ///     如果不包含,则添加
 /// </summary>
 /// <param name="this"></param>
 /// <param name="items">匹配项集合</param>
 /// <typeparam name="T">集合中元素的类型</typeparam>
 /// <exception cref="NotSupportedException"> <paramref name="this" /> maybe is read-only</exception>
 /// <example>
 ///     <code>
 ///         <![CDATA[
 /// var list = new List<string> {"aa", "bb"};
 /// list.AddIfNotContains("cc", "aa");
 /// // {"aa", "bb", "cc"}
 ///         ]]>
 ///     </code>
 /// </example>
 public static void AddIfNotContainsParams <T>(this ICollection <T> @this, params T[] items)
 {
     @this.AddIfNotContains(items);
 }