_Core/Mapper/AutoMapper.cs

(开头部分) 6KB

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

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;
using System.Xml;


namespace ComLib
{
    
    /// <summary>
    /// Class to automatically map values from one source to another source.
    /// </summary>
    public class AutoMapper
    {
        /// <summary>
        /// Default settings
        /// </summary>
        private static readonly AutoMapperSettings DefaultSettings = new AutoMapperSettings()
        {
            CatchErrors = false,
            IsCaseSensitive = false,
            MapNestedObjects = false
        };


        /// <summary>
        /// Map item from IDictionary to the type supplied.
        /// </summary>
        /// <typeparam name="T">The type to map</typeparam>
        /// <param name="map">The dictionary of key/value pairs to map from</param>
        /// <param name="item">The destination object to map values to</param>
        public static T Map<T>(IDictionary map, T item) where T : class
        {
            return Map<T>(map, item, DefaultSettings, null);
        }


        /// <summary>
        /// Map item from IDictionary to the type supplied using the settings.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="item"></param>
        /// <param name="settings"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        public static T Map<T>(IDictionary source, T item, AutoMapperSettings settings, IList<string> errors) where T : class
        {
            // Map of properties
            var propMap = AutoMapperHelper.GetPropertyMap(item.GetType(), settings.IsCaseSensitive);
            bool hasNameFilter = !string.IsNullOrEmpty(settings.NameFilter);
            string nameFilter = !hasNameFilter ? string.Empty : settings.NameFilter;
            if(!settings.IsCaseSensitive) nameFilter = nameFilter.ToLower();

            // 1. Iterate through all the keys
            foreach (DictionaryEntry keyvalue in source)
后面还有 105 行代码,解锁后查看完整代码

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

AI 解读

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

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