public RegistCheckResult Check(RegistObjectContext context) { var type = context.ObjType; var constructs = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var returnValue = new RegistCheckResult(); returnValue.IsPass = false; if (constructs.Length != 1) { returnValue.Message = string.Format("type regist as decorate must and only have 1 construct method"); return returnValue; } var contruct = constructs[0]; var parameters = contruct.GetParameters(); if (parameters.Length != 1) { returnValue.Message = string.Format("type regist as decorate the construct method must and only have 1 param "); return returnValue; } var parameter = parameters[0]; if (parameter.ParameterType != context.PType) { returnValue.Message = string.Format("type regist as decorate the construct method's param must be {0}", context.PType.Name); return returnValue; } returnValue.IsPass = true; return returnValue; }
public RegistCheckResult Check(RegistObjectContext context) { var returnValue = new RegistCheckResult(); returnValue.IsPass = false; var objType = context.ObjType; ConstructorInfo[] constructs = objType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (constructs.Length != 1) { returnValue.Message = "regist as DI Inst must and only have 1 construct method"; return returnValue; } var construct = constructs[0]; var pArray = construct.GetParameters(); foreach (var p in pArray) { if (!p.ParameterType.IsInterface) { returnValue.Message = "regsit as DI Inst the construct method\'s paramters must be interface type"; return returnValue; } } return true; }