Exemplo n.º 1
0
 /// <summary>
 /// Converts an integral representation into an enum value or indicates that it cannot.
 /// </summary>
 /// <param name="value">The integral representation to convert.</param>
 /// <param name="policy">Indicates whether invalid integral values should be returned in enum form or should be an error.</param>
 /// <param name="result">The enum value to initialize based on the casting rules.</param>
 /// <returns>true if the enum value is successfully casted, false otherwise.</returns>
 /// <exception cref="System.ArgumentException">
 ///     <paramref name="value"/> exceeds the bounds of the underlying type.
 ///     <paramref name="policy"/> contains a value not defined by the enum.
 ///</exception>
 public static bool TryCast <TValue>(ulong value, InvalidEnumPolicy policy, out TValue result) where TValue : struct, IComparable
 {
     return(EnumExt <TValue> .TryCast(value, policy, out result));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Converts a string representation into an enum value or indicates that it cannot.
 /// Accepts both integer formats in string form ([-+][digits]) or names.
 /// </summary>
 /// <param name="value">The string representation to convert.</param>
 /// <param name="ignoreCase">Indicates whether case should be ignored in conversion.</param>
 /// <param name="policy">Indicates whether invalid integral values should be returned in enum form or should be an error.</param>
 /// <param name="result">The enum value to initialize based on the parse rules.</param>
 /// <returns>true if the enum value is successfully parsed, false otherwise.</returns>
 /// <exception cref="AmbiguousEnumException"><paramref name="ignoreCase"/> is specified and multiple enum members match the specified value.</exception>
 /// <exception cref="System.ArgumentException">
 ///     <paramref name="value"/> is blank or whitespace-only.
 ///     <paramref name="policy"/> contains a value not defined by the enum.
 /// </exception>
 /// <exception cref="System.ArgumentNullException"><paramref name="value"/> is null.</exception>
 /// <exception cref="System.InvalidOperationException"><paramref name="value"/> contains flags but the enum is not a <see cref="System.FlagsAttribute"/> enum.</exception>
 public static bool TryParse <TValue>(string value, bool ignoreCase, InvalidEnumPolicy policy, out TValue result) where TValue : struct, IComparable
 {
     return(EnumExt <TValue> .TryParse(value, ignoreCase, policy, out result));
 }