src/10_Excel/Excel.Core/ExcelProviderAbstract.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Mkh.Auth.Abstractions;
using Mkh.Data.Abstractions.Entities;
using Mkh.Excel.Abstractions;
using Mkh.Excel.Abstractions.Annotations;
using Mkh.Excel.Abstractions.Export;
using Mkh.Module.Abstractions.Options;
namespace Mkh.Excel.Core;
public abstract class ExcelProviderAbstract : IExcelProvider
{
private readonly IExcelExportBuilder _exportBuilder;
private readonly IOptionsMonitor<ExcelOptions> _options;
private readonly IOptionsMonitor<CommonOptions> _commonOptions;
//导出Excel的对象的属性类型列表
private readonly ConcurrentDictionary<RuntimeTypeHandle, Dictionary<string, PropertyInfo>> _exportObjectProperties = new();
protected ExcelProviderAbstract(IOptionsMonitor<ExcelOptions> options, IOptionsMonitor<CommonOptions> commonOptions, IExcelExportBuilder exportBuilder)
{
_options = options;
_commonOptions = commonOptions;
_exportBuilder = exportBuilder;
}
/// <summary>
/// 设置列属性
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="model"></param>
private void SetColumnPropertyType<T>(ExcelExportEntityModel<T> model) where T : IEntity
{
if (model.Columns == null || !model.Columns.Any())
return;
var objectType = typeof(T);
if (!_exportObjectProperties.TryGetValue(objectType.TypeHandle, out Dictionary<string, PropertyInfo> types))
{
types = new Dictionary<string, PropertyInfo>();
var properties = objectType.GetProperties();
foreach (var property in properties)
{
if (property.GetCustomAttributes().All(m => m.GetType() != typeof(IgnoreOnExcelExportAttribute)))
{
types.Add(property.Name.ToLower(), property);
}
}
_exportObjectProperties.TryAdd(objectType.TypeHandle, types);
后面还有 81 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
