Ejemplo n.º 1
0
        /// <inheritdoc />
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            try
            {
                if (this.ResourceManager == null || this.Member == null)
                {
                    return($"{nameof(EnumExtension)} must have {nameof(this.ResourceManager)} and {nameof(this.Member)}");
                }

                if (!this.Member.GetType().IsEnum)
                {
                    return($"{nameof(EnumExtension)} {nameof(this.Member)} must be an enum");
                }

                return(StaticExtension.CreateBindingExpression(this.ResourceManager, this.Member.ToString(), serviceProvider));
            }
            catch (Exception)
            {
                return(string.Format(Resources.UnknownErrorFormat, this.Member));
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            try
            {
                if (this.ResourceManager is null || this.Member is null)
                {
                    return($"{nameof(EnumExtension)} must have {nameof(this.ResourceManager)} and {nameof(this.Member)}");
                }

                if (!this.Member.GetType().IsEnum)
                {
                    return($"{nameof(EnumExtension)} {nameof(this.Member)} must be an enum");
                }

                return(StaticExtension.CreateBindingExpression(this.ResourceManager, this.Member.ToString() !, serviceProvider));
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
#pragma warning restore CA1031 // Do not catch general exception types
            {
                return(string.Format(CultureInfo.InvariantCulture, Resources.UnknownErrorFormat, this.Member));
            }
        }