public static T?Find <T>(this IEnumerable <T> ts, Func <T, bool> pred, RequireStruct <T> _ = null) where T : struct
 {
     try
     {
         return(ts.First(pred));
     }
     catch (InvalidOperationException)
     {
         return(null);
     }
 }
 public static void EnqueueId <T>(this IBackgroundTaskQueue <VmEntityStateMessage> queue,
                                  string senderId, T entityId, string entityType, EntityOperation operation,
                                  RequireStruct <T> ignore = null)
     where T : struct
 {
     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, RequireStruct <T> ignoredArg = null) where T : struct
        {
            T?result = null;

            foreach (var value in values)
            {
                if (result.HasValue)
                {
                    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, RequireStruct <T> ignoredArg = null) where T : struct
 {
     return(values.Select(_ => (T?)_).DefaultIfEmpty(null).FirstOrDefault());
 }
示例#5
0
        public static Nullable <TResult> SelectMany <T, TMid, TResult>(this NullableOf <T> @this, Func <T, Nullable <TMid> > midSelector, Func <T, TMid, TResult> resultSelector, RequireStruct <TResult> _ = default(RequireStruct <TResult>))
            where T : class
            where TMid : struct
            where TResult : struct
        {
            if ([email protected])
            {
                return(default(Nullable <TResult>));
            }
            var mid = midSelector((T)@this);

            if (!mid.HasValue)
            {
                return(default(Nullable <TResult>));
            }
            return(resultSelector((T)@this, (TMid)mid));
        }
示例#6
0
 public static Nullable <TResult> Select <T, TResult>(this Nullable <T> @this, Func <T, TResult> func, RequireStruct <TResult> _ = default(RequireStruct <TResult>))
     where T : struct
     where TResult : struct
 {
     return(@this.HasValue ? func((T)@this) : default(Nullable <TResult>));
 }
 public static TSource FirstOrDefault_ <TSource>(this IEnumerable <TSource> source, RequireStruct <TSource> _ = default)
     where TSource : struct
 {
     return(Enumerable.FirstOrDefault(source));
 }
示例#8
0
    public static TValue GetDef <TKey, TValue>(this Dictionary <TKey, TValue> dict, TKey key, TValue defValue = default(TValue), RequireStruct <TValue> PleaseIgnoreThisParameter = null)
        where TValue : struct
    {
        if (!dict.ContainsKey(key))
        {
            return(defValue);
        }

        return(dict[key]);
    }
 public static Nullable <TSource> SingleOrNull <TSource>(this IEnumerable <TSource> source, Func <TSource, bool> predicate, RequireStruct <TSource> _ = default)
     where TSource : struct
 {
     return(source.Where(predicate).SingleOrNull());
 }
 public static TSource SingleOrDefault_ <TSource>(this IEnumerable <TSource> source, Func <TSource, bool> predicate, RequireStruct <TSource> _ = default)
     where TSource : struct
 {
     return(Enumerable.SingleOrDefault(source, predicate));
 }
 public static IEnumerable <Nullable <TSource> > NullIfEmpty <TSource>(this IEnumerable <TSource> source, RequireStruct <TSource> _ = default)
     where TSource : struct
 {
     return(source.Select(x => (Nullable <TSource>)x).DefaultIfEmpty(null));
 }
 public static Nullable <TSource> SingleOrNull <TSource>(this IEnumerable <TSource> source, RequireStruct <TSource> _ = default)
     where TSource : struct
 {
     return(Enumerable.SingleOrDefault(source.Select(x => (Nullable <TSource>)x)));
 }
示例#13
0
    public static TValue SetSafe <TKey, TValue>(this Dictionary <TKey, TValue> dict, TKey key, TValue value, RequireStruct <TValue> PleaseIgnoreThisParameter = null)
        where TValue : struct
    {
        if (!dict.ContainsKey(key))
        {
            dict.Add(key, value);
            return(value);
        }

        return(dict[key] = value);
    }
示例#14
0
 public TFinalType WithDummyVariable <TVariable>(Expression <Func <T, TVariable> > selector, TVariable?referrant = null,
                                                 RequireStruct <TVariable> reserved = null) where TVariable : struct =>
 WithDummyVariable(ExpressionPrinter.Print(selector), selector.Compile(), referrant, reserved);
 public static TSource ElementAtOrDefault_ <TSource>(this IEnumerable <TSource> source, int index, RequireStruct <TSource> _ = default)
     where TSource : struct
 {
     return(Enumerable.ElementAtOrDefault(source, index));
 }
示例#16
0
 public TFinalType WithDummyVariable <TVariable>(string name, Func <T, TVariable> selector, TVariable?referrant = null, RequireStruct <TVariable> reserved = null) where TVariable : struct =>
 InnerWithDummyVariable(name, selector, referrant);
 public static Nullable <TSource> ElementAtOrNull <TSource>(this IEnumerable <TSource> source, int index, RequireStruct <TSource> _ = default)
     where TSource : struct
 {
     return(Enumerable.ElementAtOrDefault(source.Select(x => (Nullable <TSource>)x), index));
 }
示例#18
0
 public static ChiSquaredStatisic ChiSquared <TD, TP1, TP2>(this IEnumerable <TD> data,
                                                            Func <TD, TP1> rows, Func <TD, TP2> cols, RequireStruct <TD> reserved = null) where TD : struct =>
 data.Table().WithRows("", rows).WithColumns("", cols).ChiSquared();
示例#19
0
文件: Shim.cs 项目: dr-BEat/NShim
 public static ShimBuilderStruct <T> For <T>(RequireStruct <T> _ = null) where T : struct
 {
     return(default(ShimBuilderStruct <T>));
 }