CSharp examples for System.Reflection:FieldInfo
Find Static Field Value In Assembly
using System.Reflection; using System.Linq; using System.Collections.Generic; using System;//from ww w .ja va2 s . co m public class Main{ public static IList<T> FindStaticFieldValueInAssembly<T>(this Assembly assembly, BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.Public) where T : class { IList<T> datas = new List<T>(); var fieldList = assembly.FindFieldInAssembly<T>(bindingAttr); if (fieldList.Count > 0) { fieldList.ForEach(i => { var data = i.GetValue(null) as T; if (data != null) { datas.Add(data); } }); } return datas; } }