private static List <ParamInjectInfo> GetParamInjectInfo(ParameterInfo[] paramsInfo) { List <ParamInjectInfo> paramInjectInfo = new List <ParamInjectInfo>(); for (int i = 0; i < paramsInfo.Length; i++) { ParameterInfo paramInfo = paramsInfo[i]; ParamInjectInfo injectableParamInfo; // extract inject attribute data object[] injectAttributes = paramInfo.GetCustomAttributes(attributeType: typeof(InjectAttribute), inherit: false); if (injectAttributes.Length > 0) { InjectAttribute injectAttribute = ( InjectAttribute )injectAttributes[0]; injectableParamInfo = new ParamInjectInfo(type: paramInfo.ParameterType, id: injectAttribute.ID, isOptional: injectAttribute.IsOptional); } // no inject attribute available else { injectableParamInfo = new ParamInjectInfo(type: paramInfo.ParameterType, isOptional: false); } paramInjectInfo.Add(injectableParamInfo); } return(paramInjectInfo); }
private static List <FieldInjectInfo> GetFieldInjectInfo(Type type) { List <FieldInfo> fieldInfos = GetHierarchyFieldInfo(type); List <FieldInjectInfo> fieldInjectInfos = new List <FieldInjectInfo>(); foreach (var fieldInfo in fieldInfos) { object[] injectAttributes = fieldInfo.GetCustomAttributes(attributeType: typeof(InjectAttribute), inherit: false); if (injectAttributes.Length > 0) { InjectAttribute injectAttribute = ( InjectAttribute )injectAttributes[0]; if (injectAttribute.HasID) { fieldInjectInfos.Add(new FieldInjectInfo(type: fieldInfo.FieldType, fieldInfo: fieldInfo, id: injectAttribute.ID, isOptional: injectAttribute.IsOptional)); } else { fieldInjectInfos.Add(new FieldInjectInfo(type: fieldInfo.FieldType, fieldInfo: fieldInfo, isOptional: injectAttribute.IsOptional)); } } } return(fieldInjectInfos); }