void InitGenericConverter(MethodInfo method) { if (method.GetCustomAttribute <DtoConvertAttribute>() == null) { return; } if (!method.IsGenericMethod) { return; } if (method.ReturnType != typeof(void)) { throw InvalidSignatureExceptionFactory.Create(method); } var parameters = method.GetParameters(); if (parameters.Length < 2 || parameters.Length > 3) { throw InvalidSignatureExceptionFactory.Create(method); } if (parameters[0].ParameterType.GUID != parameters[1].ParameterType.GUID) { throw InvalidSignatureExceptionFactory.Create(method); } var convertMethod = new GenericConvertMethodInfo() { Method = method, TemplateType = parameters[0].ParameterType }; //var parameterTypeUId = convertMethod.TemplateType.GUID; if (parameters.Length == 3) { convertMethod.HasContext = true; } var methodPars = method.GetParameters(); var converterName = GetGenericConverterName(convertMethod.TemplateType.GUID, methodPars[0].ParameterType, methodPars[1].ParameterType); if (!GenericConverters.TryGetValue(converterName, out List <GenericConvertMethodInfo> tList)) { GenericConverters[converterName] = new List <GenericConvertMethodInfo>(); } GenericConverters[converterName].Add(convertMethod); }
void InitValidator(MethodInfo method) { if (method.GetCustomAttribute <DtoValidateAttribute>() == null) { return; } if (method.ReturnType != typeof(void)) { throw InvalidSignatureExceptionFactory.Create(method); } var parameters = method.GetParameters(); if (parameters.Length < 1 || parameters.Length > 2) { throw InvalidSignatureExceptionFactory.Create(method); } var tFactoryType = parameters[0].ParameterType; if (!tFactoryType.IsConstructedGenericType || tFactoryType.GetGenericTypeDefinition() != typeof(ValidationRuleFactory <>)) { throw InvalidSignatureExceptionFactory.Create(method); } var dtoType = tFactoryType.GenericTypeArguments[0]; ValidationMethodInfo tValidator; if (method.IsGenericMethod) { GenericValidators[dtoType.ToString()] = tValidator = new ValidationMethodInfo() { Method = method, }; } else { Validators[dtoType] = tValidator = new ValidationMethodInfo() { Method = method, }.InitTypes(dtoType); } if (parameters.Length == 2) { tValidator.HasContext = true; } }
void InitCast(MethodInfo method) { var castAttr = method.GetCustomAttribute <DtoCastAttribute>(); if (castAttr == null) { return; } var error = DtoCopierCastStorage.CheckMethod(method); if (error != null) { throw InvalidSignatureExceptionFactory.Create(method); } Casts.Append(method, castAttr.AvailableTypes); }
void InitConverter(MethodInfo method) { if (method.GetCustomAttribute <DtoConvertAttribute>() == null) { return; } if (method.IsGenericMethod) { return; } if (method.ReturnType != typeof(void)) { throw InvalidSignatureExceptionFactory.Create(method); } var parameters = method.GetParameters(); if (parameters.Length < 2 || parameters.Length > 3) { throw InvalidSignatureExceptionFactory.Create(method); } var convertMethod = new ConvertMethodInfo() { Method = method, DstType = parameters[0].ParameterType, SrcType = parameters[1].ParameterType }; if (parameters.Length == 3) { convertMethod.HasContext = true; } if (!Converters.TryGetValue(convertMethod.DstType, out Dictionary <Type, ConvertMethodInfo> tDstList)) { Converters[convertMethod.DstType] = new Dictionary <Type, ConvertMethodInfo>(); } Converters[convertMethod.DstType][convertMethod.SrcType] = convertMethod; }