Created
July 6, 2012 02:35
-
-
Save yurenju/3057720 to your computer and use it in GitHub Desktop.
GetJsonPropertyName
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
| string GetJsonPropertyName(User user) | |
| { | |
| Type type = user.GetType(); | |
| var objProps = type.GetProperties(); | |
| foreach (var prop in user.GetType().GetProperties()) | |
| { | |
| var attrs = | |
| from attr in Attribute.GetCustomAttributes(prop) | |
| where attr is JsonPropertyAttribute | |
| select attr; | |
| foreach (JsonPropertyAttribute attr in attrs) | |
| { | |
| return attr.PropertyName; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment