/// <summary> /// Determines whether the source comparable is less than the specified other. /// </summary> /// <typeparam name="TSource">The type of the comparable.</typeparam> /// <param name="source">The source.</param> /// <param name="other">The other.</param> /// <returns> /// <c>true</c> if the source comparable is less than the comparable other; /// otherwise, <c>false</c>. /// </returns> internal static bool LessThan <TSource>(this TSource?source, TSource?other) where TSource : struct, IComparable <TSource> => source.HasValue && other.HasValue && source.Value.CompareTo(other.Value) < 0;
void ICollection <TSource?> .Add(TSource?item) { throw new NotSupportedException(); }
bool ICollection <TSource?> .Remove(TSource?item) { throw new NotSupportedException(); }
public static TResult IfHasValue <TSource, TResult>(this TSource?source, Func <TSource, TResult> f, TResult nullValue) where TSource : struct { return(source.HasValue ? f(source.Value) : nullValue); }
public TTarget?Convert(TSource?value) { return(Convert(value, null, null)); }
/// <summary> /// Retruns the <paramref name="source"/> if both <paramref name="condition"/> is true and <paramref name="source"/> is not null, or null otherwise /// </summary> /// <typeparam name="TSource">Type of source object</typeparam> /// <param name="source">Source object for operating</param> /// <param name="condition">Condition which should be checked</param> /// <returns><paramref name="source"/> if <paramref name="condition"/> is true, or null otherwise</returns> public static TSource?If <TSource>(this TSource?source, Func <TSource?, bool> condition) where TSource : struct { return(source.HasValue && condition(source) ? source : default(TSource)); }
public static TDestination Map <TSource, TDestination>(TSource?source, TDestination destination, ResolutionContext context) where TSource : struct => (source == null) ? context.Mapper.CreateObject <TDestination>() : context.Mapper.Map((TSource)source, destination);
public static Maybe <TSource> ToMaybe <TSource>(this TSource?source) where TSource : struct { return(Maybe.OfNullable(source)); }
public NullableStructAssertions(TSource?value) { Subject = value; }
/// <summary> /// Determines whether two objects are equal. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// true if the specified objects are equal; otherwise, false. /// </returns> public override bool Equals(TSource?x, TSource?y) => m_keyComparer.Equals(m_keySelector(x !) !, m_keySelector(y !) !);
protected virtual void Dispose(bool disposing) { current = default; state = -1; }
public static TSource MaxOrDefault <TSource>( [InstantHandle] this IEnumerable <TSource> source, IComparer <TSource>?comparer, TSource?defaultValue) => MinMaxOperators <TSource> .MaxOrDefault(source, comparer, defaultValue);
public static TSource MinOrDefault <TSource>( [InstantHandle] this IEnumerable <TSource> source, TSource?defaultValue) => MinMaxOperators <TSource> .MinOrDefault(source, defaultValue);
/// <summary> /// Gets conditions for any nullable struct that implements <see cref="IComparable{T}"/>. /// </summary> /// <typeparam name="TSource">The type of the nullable comparable source struct.</typeparam> /// <param name="source">The nullable comparable source struct.</param> /// <returns><see cref="INullableComparableStructCondition{TSource}"/></returns> public static INullableComparableStructCondition <TSource> IsNullableComparableStruct <TSource>(this TSource?source) where TSource : struct, IComparable <TSource> => new NullableComparableStructCondition <TSource>(source);
public static NullableStructAssertions <TSource> Should <TSource>(this TSource?actualValue) where TSource : struct { return(new NullableStructAssertions <TSource>(actualValue)); }
public static void Min_Generic_HasExpectedOutput <TSource>(IEnumerable <TSource> source, IComparer <TSource>?comparer, TSource?expected) { Assert.Equal(expected, source.Min(comparer)); }
/// <summary> /// Allows to check whether <paramref name="source"/> is not null /// </summary> /// <typeparam name="TSource">Type of source object</typeparam> /// <param name="source">Source object for checking</param> /// <returns>true if <paramref name="source"/> is not null, or false otherwise</returns> public static bool IsNotNull <TSource>(this TSource?source) where TSource : struct { return(source.HasValue); }
public static void MaxBy_Generic_RunOnce_HasExpectedOutput <TSource, TKey>(IEnumerable <TSource> source, Func <TSource, TKey> keySelector, IComparer <TKey>?comparer, TSource?expected) { Assert.Equal(expected, source.RunOnce().MaxBy(keySelector, comparer)); }
public int Compare(TSource?x, TSource?y) { return(selector(x).CompareTo(selector(y))); }
public static void Max_Generic_RunOnce_HasExpectedOutput <TSource>(IEnumerable <TSource> source, IComparer <TSource>?comparer, TSource?expected) { Assert.Equal(expected, source.RunOnce().Max(comparer)); }
public static TResult IfHasValue <TSource, TResult>(this TSource?source, Func <TSource, TResult> f) where TSource : struct { return(source.HasValue ? f(source.Value) : default(TResult)); }
public abstract TDest?Convert(TSource?value, Type targetType, TParam?parameter, CultureInfo culture);
/// <summary> /// Initializes a new instance of the <see cref="ChainableNullableComparableStructCondition{TSource}"/> class. /// </summary> /// <param name="source">The nullable comparable source object.</param> internal ChainableNullableComparableStructCondition(TSource?source) : base(source) { }
public bool Equals(TSource?x, TSource?y)
protected virtual TTarget?Convert(TSource?value, object?parameter, string?language) { throw new NotSupportedException(); }
public static List <SelectListItem> EnumToSelectList <TSource>(this TSource e, string unselectedText = null, TSource?selectedValue = null) where TSource : struct { return(((TSource?)e).EnumToSelectList(unselectedText, selectedValue)); }
public bool Contains(TSource?item) { return(item.HasValue && ContainsExtracted(item.Value)); }
public static List <SelectListItem> EnumToSelectList <TSource>(this TSource?e, string unselectedText = null, TSource?selectedValue = null) where TSource : struct { var type = typeof(TSource); var enumMembers = type.GetFields(BindingFlags.Public | BindingFlags.Static); var enumOptions = enumMembers.Select( n => { var friendlyNameAttribute = n.GetCustomAttributes(typeof(FriendlyNameAttribute), false).Cast <FriendlyNameAttribute>().FirstOrDefault(); var value = n.GetValue(e); return(new SelectListItem { Selected = selectedValue == null ? false : value.Equals(selectedValue), Text = friendlyNameAttribute == null ? value.ToString() : friendlyNameAttribute.Name, Value = value.ToString() }); }); if (unselectedText != null) { enumOptions = new[] { new SelectListItem { Value = "", Text = unselectedText, Selected = selectedValue == null } } .Union(enumOptions); } return(enumOptions.ToList()); }
/// <summary> /// Initializes a new instance of the <see cref="ChainableNullableComparableStructConditionBase{TSource,TChainableNullableComparableStructCondition,TChainableNullableComparableStructNotCondition,TChainableNullableComparableStructDoesNotCondition}"/> class. /// </summary> /// <param name="source">The comparable source object.</param> protected ChainableNullableComparableStructConditionBase(TSource?source) : base(source) { }
public bool Contains(TSource?item) { return(item != null && ContainsExtracted(item)); }