[SOLVED] Getting the name of all DataMembers in a DataContract


I am using WCF service

I have a Data Contract:

public class CustomBranches
    public int Id { get; set; }

    public string branch_name { get; set; }

    public string address_line_1 { get; set; }

    public string city_name { get; set; }

Is it possible that i can find the name of all the DataMembers in this class CustomBranches

Like “ID” , “branch name” etc



Seeing as it’s a data-contract you should most likely have all these properties available, but if not the following should list all properties of your type:

Type T =(typeof(T));
var properties = T.GetProperties(BindingFlags.Public|BindingFlags.Instance);

replace T with the type, and you’re good to go. Depending on your needs you might want different BindingFlags.

Answered By – nillls

Answer Checked By – Candace Johnson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *