Files
DP44/DataPRO/Users/UserSettings/DisplayAttributeEx.cs
2026-04-17 14:55:32 -04:00

39 lines
1.4 KiB
C#

using System.ComponentModel;
using Users.UserSettings;
// ReSharper disable once CheckNamespace
namespace DTS.Slice.Users.UserSettings
{
/// <summary>
/// this class overrides the DisplayNameAttribute to provide a translated string name, and also
/// to allow us to use an enum to create the attribute
/// to be translated a string resource should exist in the form of PropertyName_DisplayName
/// otherwise ##DisplayNameNotFound## will be returned
/// </summary>
public class DisplayAttributeEx : DisplayNameAttribute
{
private readonly PropertyEnums.PropertyIds _propertyId;
private readonly string _propertyIdString = null;
public DisplayAttributeEx(PropertyEnums.PropertyIds propertyId)
{
_propertyId = propertyId;
}
public DisplayAttributeEx(string propertyId)
{
_propertyIdString = propertyId;
}
public override string DisplayName
{
get
{
if (!string.IsNullOrWhiteSpace(_propertyIdString))
{
return StringResources.ResourceManager.GetString(_propertyIdString + "_DisplayName") ?? @"##DisplayNameNotFound##" + _propertyIdString;
}
return StringResources.ResourceManager.GetString(_propertyId + "_DisplayName") ?? @"##DisplayNameNotFound##" + _propertyId;
}
}
}
}