Getting the name of [DataMember] in C#
A slight modification to your class
[DataContract]
public class Station
{
[DataMember(Name = "stationName")]
public string StationName { get; set; }
[DataMember(Name = "stationId")]
public string StationId { get; set; }
}
and then this is how you can get it
var properties = typeof(Station).GetProperties();
foreach (var property in properties)
{
var attributes = property.GetCustomAttributes(typeof(DataMemberAttribute), true);
foreach (DataMemberAttribute dma in attributes)
{
Console.WriteLine(dma.Name);
}
}