AdvantageCMS.Core.Admin.BaseClasses Namespace
AdvantageCMS.Core.Common.BaseClasses Namespace
Build With Advantage

BusinessObjectBase..::..GetFriendlyNameForProperty Method

Gets the friendly display name for a property using its DisplayAttribute, if present. The lookup is case-insensitive and supports the GetName path so values pulled from a resource file are returned localized.

Namespace:  AdvantageCMS.Core.Admin.BaseClasses
Assembly:  AdvantageCMS.Core (in AdvantageCMS.Core.dll)

Syntax


public string GetFriendlyNameForProperty(
	string propertyName
)

Parameters

propertyName
Type: String
The name of the property to look up.

Return Value

The display name from the DisplayAttribute, or null when the property does not exist or carries no DisplayAttribute.

Examples


C#
public class AgentConfig : BusinessObject<AgentConfig>
{
    [Display(Name = "Agent Display Name")]
    public string Name { get; set; }

    public string InternalCode { get; set; } // no [Display]
}

var cfg = new AgentConfig();
string label   = cfg.GetFriendlyNameForProperty("Name");          // "Agent Display Name"
string missing = cfg.GetFriendlyNameForProperty("InternalCode");  // null (no [Display])
string unknown = cfg.GetFriendlyNameForProperty("DoesNotExist");  // null (property not found)

// Common use: render diff output with friendly column headers instead of raw property names
foreach (string propName in changedProps)
    Console.WriteLine($"{cfg.GetFriendlyNameForProperty(propName) ?? propName} changed");