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); } }
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 }); }
/// <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); }
/// <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()); }
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)); }
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>)); }
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))); }
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]); }
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()); }
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()); }
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()); }
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)); }
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); }
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]); }
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)); }
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)); }
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);
public static TSource FirstOrDefault_ <TSource>(this IEnumerable <TSource> source, RequireClass <TSource> _ = default) where TSource : class { return(Enumerable.FirstOrDefault(source) ?? Default <TSource> .Get()); }
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();
public static ShimBuilderClass <T> For <T>(RequireClass <T> _ = null) where T : class { return(default(ShimBuilderClass <T>)); }