public void Inject(object obj) { if (obj != null) { // get info Type objType = obj.GetType(); TypeInjectInfo typeInfo = TypeAnalyzer.GetTypeInjectInfo(objType); // inject InjectMethods(obj, typeInfo); InjectFields(obj, typeInfo); } }
public void Inject(object obj) { if (obj != null) { Type objType = obj.GetType(); TypeInjectInfo typeInfo = TypeAnalyzer.GetTypeInjectInfo(objType); // inject methods foreach (MethodInjectInfo methodInjectInfo in typeInfo.MethodInfo) { // get desired arguments to inject List <object> methodArguments = new List <object>(); foreach (ParamInjectInfo paramInjectInfo in methodInjectInfo.ParamInfo) { object instance; int id = (paramInjectInfo.ID.HasValue == false)? c_defaultID : paramInjectInfo.ID.Value; if (TryGet(paramInjectInfo.Type, out instance, id)) { methodArguments.Add(instance); } else { if (paramInjectInfo.IsOptional == false) { throw new InvalidOperationException(string.Format("No binding of type '{0}' with ID '{1}' exists for attempted injection '{2}'", paramInjectInfo.Type, id, methodInjectInfo.MethodInfo.Name)); } methodArguments.Add(null); } } methodInjectInfo.MethodInfo.Invoke(obj, methodArguments.ToArray()); } } }