using System.ComponentModel; using Nop.Core.Infrastructure; using Nop.Services.Localization; namespace Nop.Web.Framework.Mvc.ModelBinding; /// /// Represents model property attribute that specifies the display name by passed key of the locale resource /// [AttributeUsage(AttributeTargets.Property)] public sealed class NopResourceDisplayNameAttribute : DisplayNameAttribute, IModelAttribute { #region Fields private string _resourceValue = string.Empty; #endregion #region Ctor /// /// Create instance of the attribute /// /// Key of the locale resource public NopResourceDisplayNameAttribute(string resourceKey) : base(resourceKey) { ResourceKey = resourceKey; } #endregion #region Properties /// /// Gets or sets key of the locale resource /// public string ResourceKey { get; set; } /// /// Gets the display name /// public override string DisplayName { get { //get locale resource value _resourceValue = EngineContext.Current.Resolve().GetResourceAsync(ResourceKey).Result; return _resourceValue; } } /// /// Gets name of the attribute /// public string Name => nameof(NopResourceDisplayNameAttribute); #endregion }