CSharp examples for System.Reflection:PropertyInfo
Finds the property recursive.
// Copyright (c) Daniel Dabrowski - rod.blogsome.com. All rights reserved. using global::System.Reflection; using global::System; public class Main{ /// <summary> /// Finds the property recursive. /// </summary> /// <param name="type">The class type.</param> /// <param name="name">The property name.</param> /// <returns>PropertyInfo or null if there is no field with such name.</returns> public static PropertyInfo FindProperty(Type type, string name) {/*from ww w . j a va2s .c o m*/ if (type == null || type == typeof(object)) { // the full inheritance chain has been walked and we could // not find the Field return null; } return type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly) ?? FindProperty(type.BaseType, name); } }