Link Search Menu Expand Document

PropertyMappedNameCache


A cacher class for System.Reflection.PropertyInfo mapped names. It uses PropertyMapper internally to extract results and caches them for future use.

Use this class instead of the C# nameof(Class.Property) expression when working with property names.

Methods

Below are the methods available from this class.

FlushAllows you to flush the caches.
GetReturns the mapped name of the property.

Usability

Call the Get() method by passing a System.Reflection.PropertyInfo instance:

var properties = PropertyCache.Get<Person>();
properties
    .AsList()
    .ForEach(p =>
    {
        var mappedName = PropertyMappedNameCache.Get(p.PropertyInfo);
        // Use the 'mappedName' here
    })

Or via expression:

var mappedName = PropertyCache.Get<Person>(e => e.FirstName);
// Use the 'mappedName' here

The extraction checks for the Map attribute first, then falls back to implicit mapping, and finally uses PropertyInfo.Name from System.Reflection.