/// <summary>
 /// Initializes a new instance of the <see cref="TypeConversionMethodAttribute"/> class.
 /// </summary>
 /// <param name="t">
 /// The t.
 /// </param>
 /// <exception cref="Exception">
 /// Throws exception if the type is not an IMappingConverter
 /// </exception>
 public TypeConversionMethodAttribute(Type t)
 {
     if (typeof(IMappingConverter).IsAssignableFrom(t))
         _converter = Activator.CreateInstance(t) as IMappingConverter;
     else
         throw new Exception("Invalid IMappingConverter");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeConversionMethodAttribute"/> class.
 /// </summary>
 /// <param name="t">
 /// The t.
 /// </param>
 /// <exception cref="Exception">
 /// Throws exception if the type is not an IMappingConverter
 /// </exception>
 public TypeConversionMethodAttribute(Type t)
 {
     if (typeof(IMappingConverter).IsAssignableFrom(t))
     {
         _converter = Activator.CreateInstance(t) as IMappingConverter;
     }
     else
     {
         throw new Exception("Invalid IMappingConverter");
     }
 }
Пример #3
0
        /// <summary>
        /// Add a column mapping
        /// </summary>
        /// <param name="property">Property to map</param>
        /// <param name="columnName">Column in the table</param>
        /// <param name="mappingConverter">Converter (converts from the column type to the property type)</param>
        public void Map(Expression <Func <T, object> > property, string columnName, IMappingConverter mappingConverter)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            if (columnName == null)
            {
                throw new ArgumentNullException("columnName");
            }
            if (mappingConverter == null)
            {
                throw new ArgumentNullException("mappingConverter");
            }

            Mappings.Add(new GeneralMapping <T>(property, columnName, mappingConverter));
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneralMapping{T}" /> class.
        /// </summary>
        /// <param name="propertyInfo">The property that the mapping is for.</param>
        /// <param name="columnName">Name of the column in the table.</param>
        /// <param name="mappingConverter">Used of the column value is not of the same type as the property.</param>
        public GeneralMapping(PropertyInfo propertyInfo, string columnName, IMappingConverter mappingConverter = null)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }
            if (columnName == null)
            {
                throw new ArgumentNullException("columnName");
            }

            _propertyInfo = propertyInfo;
            PropertyName  = _propertyInfo.Name;
            ColumnName    = columnName;
            if (mappingConverter == null)
            {
                mappingConverter = new DefaultMappingConverter();
            }
            MappingConverter = mappingConverter;
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeneralMapping{T}" /> class.
 /// </summary>
 /// <param name="property">The property that the mapping is for.</param>
 /// <param name="columnName">Name of the column in the table.</param>
 /// <param name="mappingConverter">Used of the column value is not of the same type as the property.</param>
 public GeneralMapping(Expression <Func <T, object> > property, string columnName, IMappingConverter mappingConverter = null)
     : this(property != null ? (PropertyInfo)property.GetMemberInfo().Member : null, columnName, mappingConverter)
 {
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeneralMapping{T}" /> class.
 /// </summary>
 /// <param name="property">The property name that the mapping is for.</param>
 /// <param name="columnName">Name of the column in the table.</param>
 /// <param name="mappingConverter">Used of the column value is not of the same type as the property.</param>
 public GeneralMapping(string property, string columnName, IMappingConverter mappingConverter = null)
     : this(typeof(T).GetProperty(property), columnName, mappingConverter)
 {
 }