Пример #1
0
 public void ScanAssembly(Assembly assembly, ScanOptions options = null)
 {
     Type[] types = assembly.GetTypes();
     Type[] array = types;
     foreach (Type type in array)
     {
         Attribute[] customAttributes = Attribute.GetCustomAttributes(type, inherit: false);
         foreach (Attribute attribute in customAttributes)
         {
             if (options == null || options.CheckMatch(attribute))
             {
                 ScanAttribute(attribute, type, options);
             }
         }
         if (options == null || options.CheckMatch(type))
         {
             if (type.ContainsGenericParameters)
             {
                 ScanGenericType(type, options);
             }
             else
             {
                 ScanType(type, options);
             }
         }
     }
 }
Пример #2
0
 public void Scan(ScanOptions options = null)
 {
     Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
     Assembly[] array      = assemblies;
     foreach (Assembly assembly in array)
     {
         if (options == null || options.CheckMatch(assembly))
         {
             ScanAssembly(assembly, options);
         }
     }
 }
Пример #3
0
 public void ScanType(Type type, IBoundInstance instance, ScanOptions options = null)
 {
     try
     {
         BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic;
         bindingFlags = ((options != null && options.ScanStaticAndInstanceMembers) ? (bindingFlags | (BindingFlags.Instance | BindingFlags.Static)) : ((instance != null) ? (bindingFlags | BindingFlags.Instance) : (bindingFlags | BindingFlags.Static)));
         MemberInfo[] members = type.GetMembers(bindingFlags);
         MemberInfo[] array   = members;
         foreach (MemberInfo member in array)
         {
             if (options == null || options.CheckMatch(member))
             {
                 ScanMember(member, instance, options);
             }
         }
         if (options != null && !options.CheckMatch(type))
         {
             return;
         }
         foreach (Type key in processors.Keys)
         {
             if (!type.IsSubclassOf(key))
             {
                 continue;
             }
             List <BaseProcessorWrapper> list = processors[key];
             foreach (BaseProcessorWrapper item in list)
             {
                 item.ProcessType(type, instance);
             }
         }
     }
     catch (TypeLoadException)
     {
     }
 }
Пример #4
0
        public void ScanMember(MemberInfo member, IBoundInstance instance, ScanOptions options = null)
        {
            object[] customAttributes = member.GetCustomAttributes(inherit: false);
            foreach (object obj in customAttributes)
            {
                Attribute attribute = obj as Attribute;
                if ((options == null || options.CheckMatch(attribute)) && member.MemberType != MemberTypes.NestedType)
                {
                    ScanAttribute(attribute, member, instance, options);
                }
            }
            Type baseType = member.GetType().BaseType;

            if (!processors.ContainsKey(baseType))
            {
                return;
            }
            List <BaseProcessorWrapper> list = processors[baseType];

            foreach (BaseProcessorWrapper item in list)
            {
                item.ProcessMember(member, member.ReflectedType, instance);
            }
        }