Kenric Nugteren hace 1 año
padre
commit
43a41118c8
Se han modificado 2 ficheros con 18 adiciones y 1 borrados
  1. 17 0
      InABox.Core/CoreUtils.cs
  2. 1 1
      InABox.Core/Postable/PosterEngine.cs

+ 17 - 0
InABox.Core/CoreUtils.cs

@@ -2674,5 +2674,22 @@ namespace InABox.Core
 
         #endregion
 
+        #region IEnumerable Utilities
+
+        /// <summary>
+        /// Returns <paramref name="enumerable"/> as a <see cref="List{T}"/>;
+        /// if it is already a <see cref="List{T}"/>, it is directly returned, instead of copying.
+        /// </summary>
+        public static List<T> AsList<T>(this IEnumerable<T> enumerable)
+        {
+            if(enumerable is List<T> list)
+            {
+                return list;
+            }
+            return enumerable.ToList<T>();
+        }
+
+        #endregion
+
     }
 }

+ 1 - 1
InABox.Core/Postable/PosterEngine.cs

@@ -70,7 +70,7 @@ namespace InABox.Core
 
         public bool Process(IEnumerable<TPostable> posts)
         {
-            var list = posts.ToList();
+            var list = posts.AsList();
             if(list.Any(x => x.PostedStatus == PostedStatus.Posted))
             {
                 throw new RepostedException();