mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-11-29 18:38:08 +08:00
[Doc] remark and doc of support property cache #23 (via @RRQM_Home)
This commit is contained in:
parent
6517fb2d48
commit
e86c3dd9e2
@ -22,6 +22,9 @@
|
||||
|
||||
---
|
||||
|
||||
### 1.31.1
|
||||
- [OPT] Support property cache #23 (via @RRQM_Home)
|
||||
|
||||
### 1.31.0
|
||||
- [New] Support Fields #490 (via @jsgervais)
|
||||
- [New] Support skipping null values when writing to Excel #497 (via @0MG-DEN)
|
||||
|
@ -25,7 +25,8 @@
|
||||
|
||||
---
|
||||
|
||||
|
||||
### 1.31.1
|
||||
- [OPT] 支持 property cache #23 (via @RRQM_Home)
|
||||
|
||||
### 1.31.0
|
||||
|
||||
|
@ -24,6 +24,9 @@
|
||||
|
||||
---
|
||||
|
||||
### 1.31.1
|
||||
- [OPT] 支持 property cache #23 (via @RRQM_Home)
|
||||
|
||||
### 1.31.0
|
||||
- [New] 支持 Fields #490 (via @jsgervais)
|
||||
- [New] 支持是否寫入 null values cell #497 (via @0MG-DEN)
|
||||
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiniExcelLibs
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于表达式树的成员
|
||||
/// </summary>
|
||||
public abstract class Member
|
||||
{
|
||||
}
|
||||
}
|
@ -4,40 +4,20 @@ using System.Reflection;
|
||||
|
||||
namespace MiniExcelLibs
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示属性的Getter
|
||||
/// </summary>
|
||||
public class MemberGetter
|
||||
{
|
||||
/// <summary>
|
||||
/// get方法委托
|
||||
/// </summary>
|
||||
private readonly Func<object, object> m_getFunc;
|
||||
|
||||
/// <summary>
|
||||
/// 表示属性的Getter
|
||||
/// </summary>
|
||||
/// <param name="property">属性</param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public MemberGetter(PropertyInfo property)
|
||||
{
|
||||
m_getFunc = CreateGetterDelegate(property);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表示类型字段或属性的Getter
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public MemberGetter(FieldInfo fieldInfo)
|
||||
{
|
||||
m_getFunc = CreateGetterDelegate(fieldInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取属性的值
|
||||
/// </summary>
|
||||
/// <param name="instance">实例</param>
|
||||
/// <returns></returns>
|
||||
public object Invoke(object instance)
|
||||
{
|
||||
return m_getFunc.Invoke(instance);
|
||||
|
@ -4,21 +4,10 @@ using System.Reflection;
|
||||
|
||||
namespace MiniExcelLibs
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示属性的设置器
|
||||
/// </summary>
|
||||
public class MemberSetter
|
||||
{
|
||||
/// <summary>
|
||||
/// set方法委托
|
||||
/// </summary>
|
||||
private readonly Action<object, object> setFunc;
|
||||
|
||||
/// <summary>
|
||||
/// 表示属性的Getter
|
||||
/// </summary>
|
||||
/// <param name="property">属性</param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public MemberSetter(PropertyInfo property)
|
||||
{
|
||||
if (property == null)
|
||||
@ -28,12 +17,6 @@ namespace MiniExcelLibs
|
||||
setFunc = CreateSetterDelegate(property);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置属性的值
|
||||
/// </summary>
|
||||
/// <param name="instance">实例</param>
|
||||
/// <param name="value">值</param>
|
||||
/// <returns></returns>
|
||||
public void Invoke(object instance, object value)
|
||||
{
|
||||
setFunc.Invoke(instance, value);
|
||||
|
@ -6,30 +6,18 @@ using System.Reflection;
|
||||
|
||||
namespace MiniExcelLibs
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示属性
|
||||
/// </summary>
|
||||
public abstract class Member
|
||||
{
|
||||
}
|
||||
|
||||
public class Property: Member
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型属性的Setter缓存
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<Type, Property[]> m_cached = new ConcurrentDictionary<Type, Property[]>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取器
|
||||
/// </summary>
|
||||
private readonly MemberGetter m_geter;
|
||||
|
||||
/// <summary>
|
||||
/// 设置器
|
||||
/// </summary>
|
||||
private readonly MemberSetter m_seter;
|
||||
|
||||
/// <summary>
|
||||
/// 属性
|
||||
/// </summary>
|
||||
/// <param name="property">属性信息</param>
|
||||
public Property(PropertyInfo property)
|
||||
{
|
||||
Name = property.Name;
|
||||
@ -47,42 +35,18 @@ namespace MiniExcelLibs
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以读取
|
||||
/// </summary>
|
||||
public bool CanRead { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以写入
|
||||
/// </summary>
|
||||
public bool CanWrite { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取属性信息
|
||||
/// </summary>
|
||||
public PropertyInfo Info { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取属性名称
|
||||
/// </summary>
|
||||
public string Name { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 从类型的属性获取属性
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns></returns>
|
||||
public static Property[] GetProperties(Type type)
|
||||
{
|
||||
return m_cached.GetOrAdd(type, t => t.GetProperties().Select(p => new Property(p)).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取属性的值
|
||||
/// </summary>
|
||||
/// <param name="instance">实例</param>
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
/// <returns></returns>
|
||||
public object GetValue(object instance)
|
||||
{
|
||||
if (m_geter == null)
|
||||
@ -92,17 +56,11 @@ namespace MiniExcelLibs
|
||||
return m_geter.Invoke(instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置属性的值
|
||||
/// </summary>
|
||||
/// <param name="instance">实例</param>
|
||||
/// <param name="value">值</param>
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
public void SetValue(object instance, object value)
|
||||
{
|
||||
if (m_seter == null)
|
||||
{
|
||||
throw new NotSupportedException($"{Name}不允许赋值");
|
||||
throw new NotSupportedException($"{Name} can't set value");
|
||||
}
|
||||
m_seter.Invoke(instance, value);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@
|
||||
internal static List<ExcelColumnInfo> GetExcelCustomPropertyInfos(Type type, string[] keys, Configuration configuration)
|
||||
{
|
||||
List<ExcelColumnInfo> props = GetExcelPropertyInfo(type, BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance, configuration)
|
||||
.Where(prop => prop.Property.CanWrite
|
||||
.Where(prop => prop.Property.Info.GetSetMethod() != null // why not .Property.CanWrite? because it will use private setter
|
||||
&& !prop.Property.Info.GetAttributeValue((ExcelIgnoreAttribute x) => x.ExcelIgnore)
|
||||
&& !prop.Property.Info.GetAttributeValue((ExcelColumnAttribute x) => x.Ignore))
|
||||
.ToList() /*ignore without set*/;
|
||||
|
Loading…
Reference in New Issue
Block a user