Created
March 18, 2013 18:00
-
-
Save kbrammer/5189326 to your computer and use it in GitHub Desktop.
Return DataMemberAttribute names for a DataContract object or property
This file contains 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
//Returns DataMemberAttribute names for a DataContract object | |
public static List<string> GetDataMemberAttributeNames(object obj) | |
{ | |
List<string> result = new List<string>(); | |
foreach (PropertyInfo p in obj.GetType().GetProperties()) | |
{ | |
foreach (System.Runtime.Serialization.DataMemberAttribute ca in p.GetCustomAttributes(false)) | |
{ | |
result.Add((string)ca.Name); | |
} | |
} | |
return result; | |
} | |
//Returns the DataMemberAttribute name for a DataContract property | |
public static string GetDataMemberAttributeName(PropertyInfo p) | |
{ | |
string result = ""; | |
foreach (System.Runtime.Serialization.DataMemberAttribute ca in p.GetCustomAttributes(false)) | |
{ | |
result = (string)ca.Name; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment