Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class person()
- {
- public string name {get; set;}
- public int age {get; set;}
- }
- public void Check<T>(Expression<Func<T>> expr)
- {
- var body = ((MemberExpression) expr.Body);
- string name = body.Member.Name;
- }
- Check(() => person1.age);
- foreach( var property in person)
- {
- Check(() => property);
- }
- Type type = person1.GetType();
- PropertyInfo[] properties = type.GetProperties();
- foreach (PropertyInfo property in properties)
- {
- Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(person1, null));
- }
- using System.Reflection;
- // get all public static properties of MyClass type
- PropertyInfo[] propertyInfos;
- propertyInfos = typeof(person).GetProperties(BindingFlags.Public |
- BindingFlags.Static);
- // sort properties by name
- Array.Sort(propertyInfos,
- delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2)
- { return propertyInfo1.Name.CompareTo(propertyInfo2.Name); });
- foreach (PropertyInfo propertyInfo in propertyInfos)
- {
- Console.WriteLine(propertyInfo.Name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement