Пример #1
0
 /// <summary>
 ///   Gets the enum's <see cref="ExtendedEnum{TEnum}.ValueDetail">ValueDetail</see>.
 /// </summary>
 /// <typeparam name="TEnum">The enum type.</typeparam>
 /// <param name="value">The enum value.</param>
 /// <param name="includeImplicit">
 /// <para>If set to <see langword="true"/> includes implicit values of flag enums.</para>
 /// <para>By default this is set to <see langword="false"/>.</para>
 /// </param>
 /// <returns>The <see cref="ExtendedEnum{TEnum}.ValueDetail">ValueDetail</see>.</returns>
 /// <example>
 /// <code>
 ///   [Flags]
 ///   private enum Days
 ///   {
 ///       None = 0,
 ///       Fri = 1,
 ///       Sat = 1 &lt;&lt; 1,
 ///       Sun = 1 &lt;&lt; 2,
 ///       Weekend = Sat | Sun
 ///   };
 ///
 ///   Console.WriteLine(Days.Weekend.GetValueDetail());   // Outputs 'Weekend' = 3 [2 flags]
 ///   Console.WriteLine(Days.Sat.GetValueDetail());       // Outputs 'Sat' = 2
 /// </code>
 /// </example>
 /// <exception cref="ArgumentOutOfRangeException">
 ///   The enum of type <typeparamref name="TEnum"/> doesn't contain the <paramref name="value"/> specified.
 /// </exception>
 public static ExtendedEnum <TEnum> .ValueDetail GetValueDetail <TEnum>(
     this TEnum value,
     bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .GetValueDetail(value, includeImplicit));
 }
Пример #2
0
 public static IEnumerable <TEnum> SplitFlags <TEnum>(
     this TEnum flags,
     bool includeImplicit     = false,
     bool includeCombinations = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .SplitFlags(flags, includeImplicit, includeCombinations));
 }
Пример #3
0
 public static bool TryCombine <TEnum>(
     [NotNull] this IEnumerable <TEnum> flags,
     out TEnum result,
     bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .TryCombine(flags, out result, includeImplicit));
 }
Пример #4
0
 public static bool TryIntersect <TEnum>(
     this TEnum value,
     TEnum flags,
     out TEnum result,
     bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .TryIntersect(value, flags, out result, includeImplicit));
 }
Пример #5
0
 /// <summary>
 ///   Gets the enum that corresponds to the specified <see cref="ushort"/> value.
 /// </summary>
 /// <typeparam name="TEnum">The enum type.</typeparam>
 /// <param name="value">The numerical value.</param>
 /// <param name="includeImplicit">
 ///   <para>If set to <see langword="true"/> includes implicit values of flag enums.</para>
 ///   <para>By default this is set to <see langword="false"/>.</para>
 /// </param>
 /// <returns>
 /// The enum of type <typeparamref name="TEnum"/> that corresponds to the <paramref name="value"/> specified.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">
 ///   The enum of type <typeparamref name="TEnum"/> doesn't contain the raw <paramref name="value"/> specified.
 /// </exception>
 public static TEnum ToEnum <TEnum>(this ushort value, bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .GetValue(value, includeImplicit));
 }
Пример #6
0
 public static TEnum Invert <TEnum>(this TEnum value, bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .Invert(value, includeImplicit));
 }
Пример #7
0
 public static TEnum Clear <TEnum>(this TEnum value, TEnum flags, bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .Clear(value, flags, includeImplicit));
 }
Пример #8
0
 /// <summary>
 ///   Tries to get the enum's <see cref="System.ComponentModel.DescriptionAttribute"/>.
 /// </summary>
 /// <typeparam name="TEnum">The enum type.</typeparam>
 /// <param name="value">The enum value.</param>
 /// <param name="name">
 ///   <para>The description.</para>
 ///   <para>If no description is found then the output is an <see cref="String.Empty">empty string</see>.</para>
 /// </param>
 /// <returns>
 ///   Returns <see langword="true"/> if a description was found; otherwise returns <see langword="false"/>.
 /// </returns>
 /// <remarks>
 ///   If more than one enum of the same type has the same integral value all of their descriptions will
 ///   be concatenated into a single result, each on a new line.
 /// </remarks>
 public static bool TryGetDescription <TEnum>(this TEnum value, out string name)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .TryGetDescription(value, out name));
 }
Пример #9
0
 /// <summary>
 ///   Tries to get the name of an enum.
 /// </summary>
 /// <typeparam name="TEnum">The enum type.</typeparam>
 /// <param name="value">The enum value.</param>
 /// <param name="name">
 ///   <para>The name.</para>
 ///   <para>If a name isn't found then the output is <see langword="null"/>.</para>
 /// </param>
 /// <param name="includeImplicit">
 ///   <para>If set to <see langword="true"/> includes implicit values of flag enums.</para>
 ///   <para>By default this is set to <see langword="false"/>.</para>
 /// </param>
 /// <returns>
 ///   Returns <see langword="true"/> if the name was found; otherwise returns <see langword="false"/>.
 /// </returns>
 public static bool TryGetName <TEnum>(this TEnum value, out string name, bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .TryGetName(value, out name, includeImplicit));
 }
Пример #10
0
 /// <summary>
 /// Gets the <see cref="long" /> value equivalent of an enum
 /// </summary>
 /// <typeparam name="TEnum">The enum type.</typeparam>
 /// <param name="value">The enum value.</param>
 /// <param name="vLong">The long value.</param>
 /// <param name="includeImplicit"><para>If set to <see langword="true"/> includes implicit values of flag enums.</para>
 /// <para>By default this is set to <see langword="false"/>.</para></param>
 /// <returns>
 /// Returns <see langword="true" /> if the <paramref name="value" /> was found; otherwise returns <see langword="false" />.
 /// </returns>
 public static bool TryGetLong <TEnum>(this TEnum value, out long vLong, bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .TryGetLong(value, out vLong, includeImplicit));
 }
Пример #11
0
 /// <summary>
 ///   Gets a <see cref="bool"/> indicating whether the specified value is a combination flag.
 /// </summary>
 /// <typeparam name="TEnum">The type of the enum.</typeparam>
 /// <param name="value">The enum value.</param>
 /// <param name="includeImplicit">
 ///   <para>If set to <see langword="true"/> includes implicit values of flag enums.</para>
 ///   <para>By default this is set to <see langword="false"/>.</para></param>
 /// <returns>
 ///   Returns <see langword="true"/> if <paramref name="value"/> is a combination flag; otherwise returns <see langword="false"/>.
 /// </returns>
 /// <example>
 /// Example of a combination flag:
 /// <code>
 ///   [Flags]
 ///   private enum Days
 ///   {
 ///       None = 0,
 ///       Fri = 1,
 ///       Sat = 1 &lt;&lt; 1,
 ///       Sun = 1 &lt;&lt; 2,
 ///       Weekend = Sat | Sun    // Combination flag
 ///   };
 ///
 ///   Console.WriteLine(Days.Fri.IsCombinationFlag());        // Outputs false
 ///   Console.WriteLine(Days.Weekend.IsCombinationFlag());    // Outputs true
 /// </code>
 /// </example>
 public static bool IsCombinationFlag <TEnum>(this TEnum value, bool includeImplicit = false)
     where TEnum : struct, IComparable, IFormattable, IConvertible
 {
     return(ExtendedEnum <TEnum> .GetValueDetail(value, includeImplicit).Flags > 1);
 }