Jelajahi Sumber

Added AsIList() function to Core Utils, as well as creating Filters from Column instances.

Kenric Nugteren 1 tahun lalu
induk
melakukan
1356d6cfa5
3 mengubah file dengan 24 tambahan dan 0 penghapusan
  1. 13 0
      InABox.Core/CoreUtils.cs
  2. 6 0
      InABox.Core/Filter.cs
  3. 5 0
      InABox.Core/SerializableExpression.cs

+ 13 - 0
InABox.Core/CoreUtils.cs

@@ -2731,6 +2731,19 @@ namespace InABox.Core
             return enumerable.ToList<T>();
         }
 
+        /// <summary>
+        /// Returns <paramref name="enumerable"/> as an <see cref="IList{T}"/>;
+        /// if it is already a <see cref="IList{T}"/>, it is directly returned, instead of copying.
+        /// </summary>
+        public static IList<T> AsIList<T>(this IEnumerable<T> enumerable)
+        {
+            if (enumerable is IList<T> list)
+            {
+                return list;
+            }
+            return enumerable.ToList<T>();
+        }
+
         /// <summary>
         /// Returns <paramref name="enumerable"/> as an array;
         /// if it is already an array, it is directly returned, instead of copying.

+ 6 - 0
InABox.Core/Filter.cs

@@ -586,6 +586,12 @@ namespace InABox.Core
             Ands = new List<Filter<T>>();
             Ors = new List<Filter<T>>();
         }
+
+        public Filter(Column<T> column): base(column)
+        {
+            Ands = new List<Filter<T>>();
+            Ors = new List<Filter<T>>();
+        }
         
         //public Filter(object expression) : base()
         //{

+ 5 - 0
InABox.Core/SerializableExpression.cs

@@ -29,6 +29,11 @@ namespace InABox.Core
             Expression = CoreUtils.GetMemberExpression(typeof(T), property);
         }
 
+        public SerializableExpression(SerializableExpression<T> other)
+        {
+            Expression = other.Expression;
+        }
+
         public Expression Expression { get; set; }
 
         public virtual void GetObjectData(SerializationInfo info, StreamingContext context)