コード例 #1
0
        /// <summary>
        /// Searches assemblies in project for all static fields with a given attribute whose type is assignable from the given type
        /// Caches results for performance.
        /// </summary>
        public static FieldInfo[] FindStaticFieldsWithAttrAndValType <AttrType, ValType>(bool ignoreCache = false)
        {
            Type attrType = typeof(AttrType);
            Type valType  = typeof(ValType);
            var  key      = new AttrAndType(attrType, valType);

            FieldInfo[] fields;
            if (ignoreCache || !m_staticFieldsByAttrAndType.TryGetValue(key, out fields))
            {
                var fieldList = new List <FieldInfo>();
                foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
                {
                    foreach (Type t in a.GetTypes())
                    {
                        foreach (FieldInfo f in t.GetFields())
                        {
                            if (valType.IsAssignableFrom(f.FieldType))
                            {
                                foreach (var attr in f.GetCustomAttributes(false))
                                {
                                    if (attr is AttrType)
                                    {
#if BT_DEBUG_UNSTRIP
                                        Debug.Log("[" + Time.time + "] TypeUtils::FindStaticFieldsWithAttrAndValType '" + attrType.Name + "' found "
                                                  + f.DeclaringType.Name + "::" + f.Name);
#endif

                                        fieldList.Add(f);
                                    }
                                }
                            }
                        }
                    }
                }

                fields = fieldList.ToArray();
                m_staticFieldsByAttrAndType[key] = fields;
            }

            return(fields);
        }
コード例 #2
0
 override public bool Equals(object o)
 {
     if (o == this)
     {
         return(true);
     }
     else if (o == null)
     {
         return(false);
     }
     else
     {
         AttrAndType thatObj = o as AttrAndType;
         if (thatObj == null)
         {
             return(false);
         }
         else
         {
             return(this.attrType == thatObj.attrType && this.valType == thatObj.valType);
         }
     }
 }