internal void Assign(DbDataReader dbReader, object o)
 {
     if (CustomValueConverter != null)
     {
         Property.SetValue(o, CustomValueConverter(dbReader, dbReader.IsDBNull(ColumnIndex), ColumnIndex), null);
     }
     else if (ConvertMethodInfo != null)
     {
         Property.SetValue(o, ConvertMethodInfo.Invoke(o, new object[] { dbReader.IsDBNull(ColumnIndex), dbReader.GetValue(ColumnIndex) }), null);
     }
     else
     {
         Property.SetValue(o, dbReader.IsDBNull(ColumnIndex) ? null : dbReader.GetValue(ColumnIndex), null);
     }
 }
Exemplo n.º 2
0
        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;
        }