Example #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);
             }
         }
     }
 }
Example #2
0
        public IBoundInstance ScanInstance(object instance, ScanOptions options = null)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance", "Cannot scan null instance.");
            }
            IBoundInstance result = BoundInstanceFactory.Create(instance);

            ScanType(instance.GetType(), result, options);
            return(result);
        }
Example #3
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);
         }
     }
 }
Example #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);
            }
        }
Example #5
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)
     {
     }
 }
Example #6
0
        public void ScanAttribute(Attribute attribute, object reflectedObject, IBoundInstance instance, ScanOptions options = null)
        {
            Type type = attribute.GetType();

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

            foreach (BaseProcessorWrapper item in list)
            {
                if (reflectedObject is MemberInfo)
                {
                    item.ProcessAttribute(attribute, (MemberInfo)reflectedObject, instance);
                }
                else if (reflectedObject is Type)
                {
                    item.ProcessAttribute(attribute, (Type)reflectedObject, instance);
                }
            }
        }
Example #7
0
 public void ScanGenericType(Type type, IBoundInstance instance, ScanOptions options = null)
 {
 }
Example #8
0
 public void ScanAttribute(Attribute attribute, object reflectedObject, ScanOptions options = null)
 {
     ScanAttribute(attribute, reflectedObject, null, options);
 }
Example #9
0
 public void ScanMember(MemberInfo member, ScanOptions options = null)
 {
     ScanMember(member, null, options);
 }
Example #10
0
 public void ScanGenericType(Type type, ScanOptions options = null)
 {
     ScanGenericType(type, null, options);
 }