Created
May 16, 2017 20:27
-
-
Save alastairs/0f479c7471e629ea41d368ac2536036f to your computer and use it in GitHub Desktop.
Implementation of `IDisplayMetadataProvider` that reads the display name from `JsonProperty` attributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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