Get Field - CSharp System.Reflection

CSharp examples for System.Reflection:FieldInfo

Description

Get Field

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*from   w  w  w .ja v  a  2s.com*/

public class Main{
        public static FieldInfo GetField(this Type type, string name, BindingFlags bindingFlags)
        {
            return type.GetTypeInfo().DeclaredFields.FirstOrDefault(f => (f.Name == name) && IsConformWithBindingFlags(f, bindingFlags));
        }
        public static FieldInfo GetField(this Type type, string name)
        {
            return type.GetTypeInfo().DeclaredFields.FirstOrDefault(f => f.Name == name);
        }
}

Related Tutorials