Mapper/MapperHelper.cs

(开头部分) 13KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Reflection;

using ComLib.Reflection;
using ComLib.Extensions;


namespace ComLib.MapperSupport
{
    /// <summary>
    /// Helper mapper methods.
    /// </summary>
    public class MapperHelper
    {
        private static IDictionary<Type, Func<string, object>> _propertyTypeMappers = new Dictionary<Type, Func<string, object>>();


        static MapperHelper()
        {
            _propertyTypeMappers[typeof(bool)] = new Func<string, object>(StringExtensions.ToBoolObject); 
            _propertyTypeMappers[typeof(int)] = new Func<string, object>(StringExtensions.ToIntObject);
            _propertyTypeMappers[typeof(long)] = new Func<string, object>(StringExtensions.ToLongObject);
            _propertyTypeMappers[typeof(float)] = new Func<string, object>(StringExtensions.ToFloatObject);
            _propertyTypeMappers[typeof(double)] = new Func<string, object>(StringExtensions.ToDoubleObject);
            _propertyTypeMappers[typeof(TimeSpan)] = new Func<string, object>(StringExtensions.ToTimeObject);
            _propertyTypeMappers[typeof(DateTime)] = new Func<string, object>(StringExtensions.ToDateTimeObject);            
        }    
    

        /// <summary>
        /// Map the properties in the data to the properties of the item T using the propMap supplied.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item">The object to set the properties on.</param>
        /// <param name="counterOrRefId">An counter to help associate errors in mapping w/ a specific item index or reference id.</param>
        /// <param name="propMap">Property map containing the names of the properties that can be mapped.</param>
        /// <param name="data">The source of the data to map.</param>
        public static void MapTo<T>(T item, int counterOrRefId, IDictionary<string, PropertyInfo> propMap, IDictionary data)
        {
            MapTo<T>(item, counterOrRefId, propMap, data, null);
        }


        /// <summary>
        /// Map the properties in the data to the properties of the item T using the propMap supplied.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="counterOrRefId">An counter to help associate errors in mapping w/ a specific item index or reference id.</param>
        /// <param name="item">The object to set the properties on.</param>
        /// <param name="propMap">Property map containing the names of the properties that can be mapped.</param>
        /// <param name="data">The source of the data to map.</param>
        /// <param name="errors">Error collection.</param>
        public static void MapTo<T>(T item, int counterOrRefId, IDictionary<string, PropertyInfo> propMap, IDictionary data, IErrors errors)
        {
            var handledProps = new Dictionary<string, bool>();
后面还有 227 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。