コード例 #1
0
 public static T Find <T>(this IEnumerable <T> ts, Func <T, bool> pred, RequireClass <T> _ = null) where T : class
 {
     try
     {
         return(ts.First(pred));
     }
     catch (InvalidOperationException)
     {
         return(null);
     }
 }
コード例 #2
0
 public static void EnqueueId <T>(this IBackgroundTaskQueue <VmEntityStateMessage> queue,
                                  string senderId, T entityId, string entityType, EntityOperation operation,
                                  RequireClass <T> ignore = null)
     where T : class
 {
     queue.Enqueue(new VmEntityStateMessage
     {
         SenderId   = senderId,
         EntityIds  = new object[] { entityId },
         EntityType = entityType,
         Operation  = operation
     });
 }
コード例 #3
0
        /// <summary>
        /// Возвращает если элементов в перечислении values в кол-ве не 1 - mull
        /// или значение, содержащееся в первом и единственном элементе.
        /// </summary>
        /// <param name="values">Обычно значение полученное из NullableToEnumerable и цепочки преобразований</param>
        /// <returns>Единичное значение или null</returns>
        public static T SingleOrNull <T>(this IEnumerable <T> values, RequireClass <T> ignoredArg = null) where T : class
        {
            T result = null;

            foreach (var value in values)
            {
                if (!(result is null))
                {
                    return(null);
                }
                result = value;
            }
            return(result);
        }
コード例 #4
0
 /// <summary>
 /// Возвращает для входного параметра с пустым перечислителем IEnumerable mull
 /// или значение, содержащееся в первом элементе.
 /// </summary>
 /// <param name="values">Обычно значение полученное из NullableToEnumerable и цепочки преобразований</param>
 /// <returns>Единичное значение или null</returns>
 public static T FirstOrNull <T>(this IEnumerable <T> values, RequireClass <T> ignoredArg = null) where T : class
 {
     return(values.DefaultIfEmpty(null).FirstOrDefault());
 }
コード例 #5
0
        public static NullableOf <TResult> SelectMany <T, TMid, TResult>(this NullableOf <T> @this, Func <T, Nullable <TMid> > midSelector, Func <T, TMid, TResult> resultSelector, RequireClass <TResult> _ = default(RequireClass <TResult>))
            where T : class
            where TMid : struct
            where TResult : class
        {
            if ([email protected])
            {
                return(default(NullableOf <TResult>));
            }
            var mid = midSelector((T)@this);

            if (!mid.HasValue)
            {
                return(default(NullableOf <TResult>));
            }
            return(resultSelector((T)@this, (TMid)mid));
        }
コード例 #6
0
 public static NullableOf <TResult> Select <T, TResult>(this Nullable <T> @this, Func <T, TResult> func, RequireClass <TResult> _ = default(RequireClass <TResult>))
     where T : struct
     where TResult : class
 {
     return(@this.HasValue ? func((T)@this) : default(NullableOf <TResult>));
 }
コード例 #7
0
 public static NullableOf <TSource> FirstOrNull <TSource>(this IEnumerable <TSource> source, RequireClass <TSource> _ = default)
     where TSource : class
 {
     return(Enumerable.FirstOrDefault(source.Select(x => (NullableOf <TSource>)x)));
 }
コード例 #8
0
    public static TValue GetSafe <TKey, TValue>(this Dictionary <TKey, TValue> dict, TKey key, TValue defValue = null, RequireClass <TValue> PleaseIgnoreThisParameter = null)
        where TValue : class, new()
    {
        if (!dict.ContainsKey(key))
        {
            dict.Add(key, defValue == null ? new TValue() : defValue);
        }

        return(dict[key]);
    }
コード例 #9
0
 public static TSource ElementAtOrDefault_ <TSource>(this IEnumerable <TSource> source, int index, RequireClass <TSource> _ = default)
     where TSource : class
 {
     return(Enumerable.ElementAtOrDefault(source, index) ?? Default <TSource> .Get());
 }
コード例 #10
0
 public static NullableOf <TSource> SingleOrNull <TSource>(this IEnumerable <TSource> source, Func <TSource, bool> predicate, RequireClass <TSource> _ = default)
     where TSource : class
 {
     return(source.Where(predicate).SingleOrNull());
 }
コード例 #11
0
 public static TSource SingleOrDefault_ <TSource>(this IEnumerable <TSource> source, Func <TSource, bool> predicate, RequireClass <TSource> _ = default)
     where TSource : class
 {
     return(Enumerable.SingleOrDefault(source, predicate) ?? Default <TSource> .Get());
 }
コード例 #12
0
 public static IEnumerable <NullableOf <TSource> > NullIfEmpty <TSource>(this IEnumerable <TSource> source, RequireClass <TSource> _ = default)
     where TSource : class
 {
     return(source.Select(x => (NullableOf <TSource>)x).DefaultIfEmpty(null));
 }
コード例 #13
0
    public static TValue SetSafe <TKey, TValue>(this Dictionary <TKey, TValue> dict, TKey key, TValue value, RequireClass <TValue> PleaseIgnoreThisParameter = null)
        where TValue : class
    {
        if (!dict.ContainsKey(key))
        {
            dict.Add(key, value);
            return(value);
        }

        return(dict[key] = value);
    }
コード例 #14
0
    public static TValue GetDef <TKey, TValue>(this Dictionary <TKey, TValue> dict, TKey key, TValue defValue = null, RequireClass <TValue> PleaseIgnoreThisParameter = null)
        where TValue : class
    {
        if (!dict.ContainsKey(key))
        {
            return(defValue);
        }

        return(dict[key]);
    }
コード例 #15
0
 public TFinalType WithDummyVariable <TVariable>(string name, Func <T, TVariable> selector, TVariable referrant = null, RequireClass <TVariable> reserved = null) where TVariable : class
 {
     Filter.AddFilter(selector);
     return(InnerWithDummyVariable(name, selector, referrant));
 }
コード例 #16
0
 public static NullableOf <TSource> ElementAtOrNull <TSource>(this IEnumerable <TSource> source, int index, RequireClass <TSource> _ = default)
     where TSource : class
 {
     return(Enumerable.ElementAtOrDefault(source.Select(x => (NullableOf <TSource>)x), index));
 }
コード例 #17
0
 public TFinalType WithDummyVariable <TVariable>(Expression <Func <T, TVariable> > selector, TVariable referrant = null,
                                                 RequireClass <TVariable> reserved = null) where TVariable : class =>
 WithDummyVariable(ExpressionPrinter.Print(selector), selector.Compile(), referrant, reserved);
コード例 #18
0
 public static TSource FirstOrDefault_ <TSource>(this IEnumerable <TSource> source, RequireClass <TSource> _ = default)
     where TSource : class
 {
     return(Enumerable.FirstOrDefault(source) ?? Default <TSource> .Get());
 }
コード例 #19
0
 public static ChiSquaredStatisic ChiSquared <TD, TP1, TP2>(this IEnumerable <TD> data,
                                                            Func <TD, TP1> rows, Func <TD, TP2> cols, RequireClass <TD> reserved = null) where TD : class =>
 data.Table().WithRows("", rows).WithColumns("", cols).ChiSquared();
コード例 #20
0
ファイル: Shim.cs プロジェクト: dr-BEat/NShim
 public static ShimBuilderClass <T> For <T>(RequireClass <T> _ = null) where T : class
 {
     return(default(ShimBuilderClass <T>));
 }