Find Field Throughout Hierarchy - CSharp System.Reflection

CSharp examples for System.Reflection:FieldInfo

Description

Find Field Throughout Hierarchy

Demo Code


using System.Reflection;
using System.Collections.Generic;
using System;/*from  w  ww .ja v a2  s .c  om*/

public class Main{
        public static FieldInfo FindFieldThroughoutHierarchy(Type type, string name)
        {
            FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
            if (field == null && type.GetCustomAttributes(_includeBaseAttributeType, false).Length > 0)
            {
                field = FindFieldThroughoutHierarchy(type.BaseType, name);
            }
            return field;
        }
}

Related Tutorials