c# - How to get all Property name only in a Class -
How can I get all the assets of the following classes:
public class employees { Int employee id; last name; // (20) character only the first string; // (10) characters are only string titles; // (30) character only string address; // (60) characters only string city; // (15) characters are only string fields; // (15) characters only string postalCode; // (10) characters only string country; // (15) characters only string extension; // (4) characters only string homePhone; Public Entrepreneur ID {Return Worker Id; } Set {employeeID = value; }} Public String LastName {get {return lastName; } Set {lastName = value; }} Public string first name {get {return firstName; } Set {firstName = value; }} Get the public string title {return {return title; } Set {title = value; }} To get the public string address {return address; } Set {address = value; }} Public string city {return city; } Set {city = value; }} Public string field {Get return area; } Set {region = value; }} Public string postal code ({return postcode;} set {postalCode = value;}} public string country {return country}} set {country = value;}} public string extension {get {return extension};} set {extension = value;}} Public string homepages {Back {home home phone;} set {homePhone = value; I tried to use reflection / property information but with a slight problem, the data type is included in the list: public propertyInfo [] getPropertyInfo () {propertyIn O [property] property; propertyInfos = typeof (employee) .GetProperties (); Return Property InfoS;}
Thank you in advance.
Your method gives a PropertyInfo data structure for each property, including information such as property name, property return type, etc. If you just want the name Are, then x Please. For the collection of property names, the LINQ select extension method can be used: Var propertyNames = getPropertyInfo (). Select (P = & gt; p.Name) .Oolist (); You can use the code to reduce the amount of code in your class: ... public string LastName { get; Set; } // should be (20) characters only public string FirstName {get; Set; } // should be (10) only characters ...
Comments
Post a Comment