Esempio n. 1
0
 /// <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;
Esempio n. 2
0
 void ICollection <TSource?> .Add(TSource?item)
 {
     throw new NotSupportedException();
 }
Esempio n. 3
0
 bool ICollection <TSource?> .Remove(TSource?item)
 {
     throw new NotSupportedException();
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 public TTarget?Convert(TSource?value)
 {
     return(Convert(value, null, null));
 }
Esempio n. 6
0
 /// <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));
 }
Esempio n. 7
0
 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 !) !);
Esempio n. 11
0
 protected virtual void Dispose(bool disposing)
 {
     current = default;
     state   = -1;
 }
Esempio n. 12
0
 public static TSource MaxOrDefault <TSource>(
     [InstantHandle] this IEnumerable <TSource> source,
     IComparer <TSource>?comparer,
     TSource?defaultValue) =>
 MinMaxOperators <TSource> .MaxOrDefault(source, comparer, defaultValue);
Esempio n. 13
0
 public static TSource MinOrDefault <TSource>(
     [InstantHandle] this IEnumerable <TSource> source,
     TSource?defaultValue) =>
 MinMaxOperators <TSource> .MinOrDefault(source, defaultValue);
Esempio n. 14
0
 /// <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);
Esempio n. 15
0
 public static NullableStructAssertions <TSource> Should <TSource>(this TSource?actualValue)
     where TSource : struct
 {
     return(new NullableStructAssertions <TSource>(actualValue));
 }
Esempio n. 16
0
 public static void Min_Generic_HasExpectedOutput <TSource>(IEnumerable <TSource> source, IComparer <TSource>?comparer, TSource?expected)
 {
     Assert.Equal(expected, source.Min(comparer));
 }
Esempio n. 17
0
 /// <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);
 }
Esempio n. 18
0
 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));
 }
Esempio n. 19
0
 public int Compare(TSource?x, TSource?y)
 {
     return(selector(x).CompareTo(selector(y)));
 }
Esempio n. 20
0
 public static void Max_Generic_RunOnce_HasExpectedOutput <TSource>(IEnumerable <TSource> source, IComparer <TSource>?comparer, TSource?expected)
 {
     Assert.Equal(expected, source.RunOnce().Max(comparer));
 }
Esempio n. 21
0
 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)
Esempio n. 25
0
 protected virtual TTarget?Convert(TSource?value, object?parameter, string?language)
 {
     throw new NotSupportedException();
 }
Esempio n. 26
0
 public static List <SelectListItem> EnumToSelectList <TSource>(this TSource e, string unselectedText = null, TSource?selectedValue = null)
     where TSource : struct
 {
     return(((TSource?)e).EnumToSelectList(unselectedText, selectedValue));
 }
Esempio n. 27
0
 public bool Contains(TSource?item)
 {
     return(item.HasValue && ContainsExtracted(item.Value));
 }
Esempio n. 28
0
        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)
 {
 }
Esempio n. 30
0
 public bool Contains(TSource?item)
 {
     return(item != null && ContainsExtracted(item));
 }