コード例 #1
0
        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));
                        }
                    }
                }
            }
        }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
			public override void Load() {
				TextInt.Value = (int)Fi.GetValue (Data);
			}
コード例 #7
0
			public override void Load () {
				_toggle = (bool)Fi.GetValue (Data);
			}
コード例 #8
0
			public override void Load () {
				TextMatrix.Value = (Matrix4x4)Fi.GetValue (Data);
			}
コード例 #9
0
			public override void Load () {
				TextVector.Value = (Color)Fi.GetValue (Data);
			}
コード例 #10
0
			public override void Load() {
				TextFloat.Value = (float)Fi.GetValue(Data);
			}
コード例 #11
0
 public override void Load()
 {
     text = (string)Fi.GetValue(Data);
 }