Skip to content

Instantly share code, notes, and snippets.

@yurenju
Created July 6, 2012 02:35
Show Gist options
  • Select an option

  • Save yurenju/3057720 to your computer and use it in GitHub Desktop.

Select an option

Save yurenju/3057720 to your computer and use it in GitHub Desktop.
GetJsonPropertyName
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