Наша сборка Qt VS Tools
giy
2022-09-02 ca47896204482bf4a6979e3838bf7f09f61cebeb
QtVsTools.Core/Common/EnumExt.cs
@@ -40,6 +40,8 @@
    /// </summary>
    public static class EnumExt
    {
        static LazyFactory StaticLazy { get; } = new LazyFactory();
        /// <summary>
        /// Wrapper for enum cast values.
        /// </summary>
@@ -64,7 +66,7 @@
        [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; }
        }
@@ -128,8 +130,7 @@
        /// </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>
@@ -201,15 +202,14 @@
                .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)
            });