コード例 #1
0
        public RegistCheckResult Check(RegistObjectContext context)
        {
            var type = context.ObjType;
            var constructs = type.GetConstructors();
            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;

        }
コード例 #2
0
ファイル: DIInstCreator.cs プロジェクト: deboe2015/Ctrip.SOA
        public RegistCheckResult Check(Ctrip.SOA.Infratructure.IOCFactoryModel.RegistObjectContext context)
        {
            var returnValue = new RegistCheckResult();
            returnValue.IsPass = false;

            var objType = context.ObjType;

            ConstructorInfo[] constructs = objType.GetConstructors();
            if (constructs.Length != 1)
            {
                returnValue.Message = string.Format("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 = string.Format("regsit as DI Inst the construct method's paramters must be interface type");
                    return returnValue;
                }
            }
            return true;
        }