void ParsePropertyAttributes(Type type, InjectionInfo info) { var properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy); for (int i = 0; i < properties.Length; i++) { var property = properties[i]; ParseAttributes(property, property.PropertyType, info); } }
void ParseFieldAttributes(Type type, InjectionInfo info) { var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy); for (int i = 0; i < fields.Length; i++) { var field = fields[i]; ParseAttributes(field, field.FieldType, info); } }
public InjectionInfo Parse(Type type) { var info = new InjectionInfo(); ParsePropertyAttributes(type, info); ParseFieldAttributes(type, info); ParseMethodAttributes <PostInjection>(type, info); ParseMethodAttributes <Cleanup>(type, info); return(info); }
void ParseAttributes(MemberInfo memberInfo, Type type, InjectionInfo info) { var customAttributes = memberInfo.GetCustomAttributes(true); for (int i = 0; i < customAttributes.Length; i++) { if (customAttributes[i] is Inject) { info.AddInjection(memberInfo.Name, type); } } }
void ParseMethodAttributes <T> (Type type, InjectionInfo info) where T : Attribute { var methods = type.GetMethods(); IList <MethodInfo> taggedMethods = null; for (int i = 0; i < methods.Length; i++) { var method = methods[i]; var attributes = method.GetCustomAttributes(true); for (int j = 0; j < attributes.Length; j++) { if (attributes[j] is T) { taggedMethods = taggedMethods ?? info.GetCalls <T>(); taggedMethods.Add(method); } } } }
InjectionInfo ParseInfo(Type type) { IDictionary <string, Type> properties = GetPropertyInjections(type.GetProperties()); IDictionary <string, Type> fields = GetFieldInjections(type.GetFields()); IList <MethodInfo> posts = GetPostInjections(type.GetMethods()); InjectionInfo info = null; if (properties != null || fields != null || posts != null) { info = new InjectionInfo { properties = properties, fields = fields, postInjections = posts }; } return(info); }