| | |
| | | /// </summary>
|
| | | public static class EnumExt
|
| | | {
|
| | | static LazyFactory StaticLazy { get; } = new LazyFactory();
|
| | |
|
| | | /// <summary>
|
| | | /// Wrapper for enum cast values.
|
| | | /// </summary>
|
| | |
| | | [AttributeUsage(AttributeTargets.All)]
|
| | | public sealed class StringAttribute : Attribute, ICast<string>
|
| | | {
|
| | | public string Value { get; private set; }
|
| | | public string Value { get; }
|
| | | public StringAttribute(string str) { Value = str; }
|
| | | }
|
| | |
|
| | |
| | | /// </summary>
|
| | | public static TEnum Cast<T, TEnum>(this T valueT, TEnum defaultValue) where TEnum : struct
|
| | | {
|
| | | TEnum value;
|
| | | return TryCast(valueT, out value) ? value : defaultValue;
|
| | | return TryCast(valueT, out TEnum value) ? value : defaultValue;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | .FirstOrDefault();
|
| | | }
|
| | |
|
| | | static IEnumerable<Type> _CastAttribTypes;
|
| | | /// <summary>
|
| | | /// List of cast attribute types.
|
| | | /// </summary>
|
| | | /// <remarks>
|
| | | /// Future cast attribute types need to be added to this list.
|
| | | /// </remarks>
|
| | | static IEnumerable<Type> CastAttribTypes => _CastAttribTypes
|
| | | ?? (_CastAttribTypes = new[]
|
| | | static IEnumerable<Type> CastAttribTypes => StaticLazy.Get(() =>
|
| | | CastAttribTypes, () => new[]
|
| | | {
|
| | | typeof(StringAttribute)
|
| | | });
|