src/DotNetCommon.Core/MapperHelper.cs
(开头部分) 69KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using DotNetCommon.Extensions;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Text.Json;
using static System.Net.Mime.MediaTypeNames;
namespace DotNetCommon
{
/// <summary>
/// Mapper帮助类,参照: <seealso cref="MapperHelper.Mapper(Type, Type, object, bool, bool)"/>
/// </summary>
public class MapperHelper
{
/// <summary>
/// Mapper时用的缓存字典,内部封装了 ConcurrentDictionary<object, object>,由 containsRepeatReference 决定是否使用内部的字典
/// </summary>
public class CacheDictionary
{
private readonly ConcurrentDictionary<(Type from, Type dest, object obj), object> dic;
private readonly bool containsRepeatReference = true;
public CacheDictionary(bool containsRepeatReference, int capacity = 1024)
{
this.containsRepeatReference = containsRepeatReference;
if (containsRepeatReference) dic = new ConcurrentDictionary<(Type from, Type dest, object obj), object>(1, capacity);
}
public bool ContainsKey((Type from, Type dest, object obj) key)
{
if (!containsRepeatReference) return false;
return dic.ContainsKey(key);
}
public void Add((Type from, Type dest, object obj) key, object value)
{
if (!containsRepeatReference) return;
dic.TryAdd(key, value);
}
public object get_Item((Type from, Type dest, object obj) obj)
{
if (!containsRepeatReference) return null;
return dic.ContainsKey(obj) ? dic[obj] : null;
}
public void set_Item((Type from, Type dest, object obj) key, object val)
{
if (!containsRepeatReference) return;
dic.TryAdd(key, val);
}
}
class Wrapper
{
后面还有 1143 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
