public static void InitAllTypeInstances <TChild>(object instance) { if (instance == null) { return; } var Thost = instance.GetType(); var t = typeof(TChild); foreach (var Fi in Thost .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(fi => t.IsAssignableFrom(fi.FieldType)).ToList()) { if (Fi.FieldType != typeof(Type)) { var it = (TChild)Fi.GetValue(instance); if (it == null) { if (typeof(INode).IsAssignableFrom(Fi.FieldType)) { Fi.SetValue(instance, (TChild)CreateNode(instance, Fi.FieldType)); } else { Fi.SetValue(instance, (TChild)Activator.CreateInstance(Fi.FieldType)); } } } } }
public static int ValueFromEnumeration(Type enumeration, String strValue) { foreach (FieldInfo Fi in enumeration.GetFields(BindingFlags.Public | BindingFlags.Static)) { if (Fi.GetValue(enumeration).ToString() == strValue) { return((int)Fi.GetValue(enumeration)); } } return(-1); }
public static Boolean ExistsInEnumeration(Type enumeration, String strValue) { foreach (FieldInfo Fi in enumeration.GetFields(BindingFlags.Public | BindingFlags.Static)) { if (Fi.GetValue(enumeration).ToString().ToUpper() == strValue.ToUpper()) { return(true); } } return(false); }
public static Dictionary <string, FieldDescriptor <Tbase> > GetAllTypeInstancesBasedOn <Tbase>(Group instance) { var t = typeof(Tbase); var allFields = new Dictionary <string, FieldDescriptor <Tbase> >(); var Thost = instance.GetType(); foreach (var Fi in Thost .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(fi => t.IsAssignableFrom(fi.FieldType)).ToList()) { allFields.Add( Fi.Name, new FieldDescriptor <Tbase> { Value = (Tbase)Fi.GetValue(instance), Attributes = Fi.GetCustomAttributes(typeof(Attribute), true).Cast <Attribute>().ToList() } ); } t = typeof(List <Tbase>); foreach (var Fi in Thost .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(fi => fi.FieldType.IsList()).ToList()) { var tp = Fi.FieldType.GenericTypeArguments.First(); if (tp == typeof(Tbase)) { var it = Fi.GetValue(instance); var l = (List <Tbase>)Fi.GetValue(instance); var iterator = 0; if (l != null) { l.ForEach( i => allFields.Add( Fi.Name + "_" + iterator++, new FieldDescriptor <Tbase> { Value = i, Attributes = Fi.GetCustomAttributes(typeof(Attribute), true).Cast <Attribute>().ToList() } ) ); } } } return(allFields); }
/// <summary> /// Method used to get the enumeration values and names in the key value data table. /// It returns Key Value Datatable containing enumeration keys in its value column and enumeration values /// in its key column /// </summary> /// <param name="enumType"></param> /// <returns>Datatable containing enumeration keys in its value column and enumeration values /// in its key column /// </returns> public static Dictionary <String, string> GetEnumerationDataTable(Type enumeration, Boolean IncludeEmptyRow = false) { Dictionary <String, string> dtKeyValue = new Dictionary <String, string>(); int i = 1; if (IncludeEmptyRow) { dtKeyValue.Add("", " "); } foreach (FieldInfo Fi in enumeration.GetFields(BindingFlags.Public | BindingFlags.Static)) { dtKeyValue.Add(Fi.GetValue(enumeration).ToString(), Fi.GetValue(enumeration).ToString()); } return(dtKeyValue); }
public override void Load() { TextInt.Value = (int)Fi.GetValue (Data); }
public override void Load () { _toggle = (bool)Fi.GetValue (Data); }
public override void Load () { TextMatrix.Value = (Matrix4x4)Fi.GetValue (Data); }
public override void Load () { TextVector.Value = (Color)Fi.GetValue (Data); }
public override void Load() { TextFloat.Value = (float)Fi.GetValue(Data); }
public override void Load() { text = (string)Fi.GetValue(Data); }