Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alastairs/0f479c7471e629ea41d368ac2536036f to your computer and use it in GitHub Desktop.
Save alastairs/0f479c7471e629ea41d368ac2536036f to your computer and use it in GitHub Desktop.
Implementation of `IDisplayMetadataProvider` that reads the display name from `JsonProperty` attributes.
namespace Mvc.Examples
{
internal class JsonPropertyDisplayMetadataProvider : IDisplayMetadataProvider
{
public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
{
var attributes = context.Attributes;
var jsonPropertyAttribute = attributes.OfType<JsonPropertyAttribute>().FirstOrDefault();
var displayMetadata = context.DisplayMetadata;
displayMetadata.DisplayName = () => jsonPropertyAttribute.PropertyName;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment