Пример #1
0
        /// <summary>Adds a property/field to the mapping.</summary>
        /// <typeparam name="T">The <see cref="Type"/> associated with the column mapping.</typeparam>
        /// <param name="mappedType">
        ///     An instance of <see cref="IMappedType{T}"/> containing the current mapping.
        /// </param>
        /// <param name="propertyName">
        ///     The name of the property/field to add to the mapping.
        /// </param>
        /// <returns>
        ///     An instance of <see cref="PropertyMapping{T}"/> mapped to the property/field
        ///     specified in the <paramref name="propertyName"/> parameter.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if the <paramref name="mappedType"/> or <paramref name="propertyName"/> parameter
        ///     is <c>null</c>, an empty string, or only consists of white-space characters.
        /// </exception>
        public static PropertyMapping <T> MapProperty <T>(this IMappedType <T> mappedType, string propertyName)
        {
            if (mappedType == null)
            {
                throw new ArgumentNullException(nameof(mappedType));
            }

            if (String.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            var propertyMapping = new PropertyMapping <T>() as IPropertyMapping <T>;

            propertyMapping.MappedType   = mappedType;
            propertyMapping.PropertyName = propertyName;

            return(propertyMapping as PropertyMapping <T>);
        }
Пример #2
0
        /// <summary>Maps the specified column name to the provided property/field.</summary>
        /// <typeparam name="T">The <see cref="Type"/> associated with the column mapping.</typeparam>
        /// <param name="propertyMapping">The <see cref="PropertyMapping{T}"/> to associate the column name with.</param>
        /// <param name="columnName">The name of the column to map to the property/field.</param>
        /// <returns>
        ///     An instance of <see cref="ColumnMapping{T}"/> with the column name specified in the
        ///     <paramref name="columnName"/> parameter mapped to the property/field specified in
        ///     the <paramref name="propertyName"/> parameter.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if the <paramref name="propertyMapping"/> parameter is <c>null</c>.
        /// </exception>
        public static ColumnMapping <T> ToColumn <T>(this PropertyMapping <T> propertyMapping, string columnName)
        {
            if (propertyMapping == null)
            {
                throw new ArgumentNullException(nameof(propertyMapping));
            }

            var propMapping = propertyMapping as IPropertyMapping <T>;

            propMapping.MappedType[propMapping.PropertyName] = columnName;

            var columnMapping = new ColumnMapping <T>() as IColumnMapping <T>;

            columnMapping.MappedType   = propMapping.MappedType;
            columnMapping.PropertyName = propMapping.PropertyName;
            columnMapping.ColumnName   = columnName;
            columnMapping.MappedType.DefineColumnMapping(columnMapping);

            return(columnMapping as ColumnMapping <T>);
        }