Esempio n. 1
0
 public static void NotNullOrEmpty <T>(IEnumerable <T> arg, string name)
 {
     if (CollectionUtil.IsNullOrEmpty(arg))
     {
         throw new ArgumentException("Argument is null or empty.", name);
     }
 }
Esempio n. 2
0
 public static void NotNullOrEmpty <T>(IEnumerable <T> arg, string name, string message)
 {
     if (CollectionUtil.IsNullOrEmpty(arg))
     {
         throw new ArgumentException(message, name);
     }
 }
Esempio n. 3
0
        public static int Calculate <T>(IEnumerable <T> collection)
        {
            if (CollectionUtil.IsNullOrEmpty(collection))
            {
                return(0);
            }

            var list = collection as IList <T>;

            if (list != null)
            {
                int hash = Get(list[0]);
                for (int i = 1; i < list.Count; ++i)
                {
                    hash = Combine(hash, Get(list[i]));
                }
                return(hash);
            }
            else
            {
                int hash = 0;
                foreach (var item in collection)
                {
                    hash = Combine(hash, Get(item));
                }
                return(hash);
            }
        }
        /// <summary>
        ///     Appends an array of characters with indentation which defined by specified indent level and unit.
        /// </summary>
        /// <param name="self"> The <see cref="StringBuilder" /> to append to. </param>
        /// <param name="value"> The array of characters to append. </param>
        /// <param name="indentLevel"> Number of unit string to append. </param>
        /// <param name="indentUnit"> Unit string of each indent level. </param>
        /// <returns> The <paramref name="self" /> instance. </returns>
        public static StringBuilder IndentedAppend(
            this StringBuilder self, char[] value, byte indentLevel, string indentUnit)
        {
            if (indentLevel == 0)
            {
                return(self.Append(value));
            }

            if (CollectionUtil.IsNullOrEmpty(value))
            {
                return(self);
            }

            self.AppendHeadIndent(indentLevel, indentUnit);

            int count = value.Length;

            for (int i = 0; i < count; ++i)
            {
                var c = value[i];
                self.Append(c);
                if (c == '\n' && i != count - 1)
                {
                    self.AppendIndent(indentLevel, indentUnit);
                }
            }
            return(self);
        }
Esempio n. 5
0
 private static IEnumerable <Type> EnumerateTypes(
     Func <Type, IEnumerable <Type>, IEnumerable <Type> > method, Type type, IEnumerable <Assembly> assemblies)
 {
     if (CollectionUtil.IsNullOrEmpty(assemblies))
     {
         assemblies = new[] { type.Assembly }
     }
     ;
     return(method(type, assemblies.Where(a => a != null).Distinct().SelectMany(a => a.GetTypes())));
 }
Esempio n. 6
0
        public static Type GetType(string name, params Assembly[] searchAssemblies)
        {
            Ensure.Argument.NotNullOrEmpty(name, "name");

            if (CollectionUtil.IsNullOrEmpty(searchAssemblies))
            {
                searchAssemblies = DefaultSearchAssemblies;
            }

            Type type;

            if (!typesByName.TryGetValue(name, out type))
            {
                type = MakeType(TypeName.Get(name), searchAssemblies);
                if (type != null)
                {
                    typesByName.Add(name, type);
                }
            }
            return(type);
        }
Esempio n. 7
0
 public static int Get <T>(IEnumerable <T> objects)
 => CollectionUtil.IsNullOrEmpty(objects) ? 0 : Combine(objects.Select((Func <T, int>)Get));