src/DotNetCommon.Core/Accessors/ObjectAccessor.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace DotNetCommon.Accessors
{
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
/// <summary>
/// 快速访问给定类型的对象的属性值, 参照: <seealso cref="Accessor"/>
/// </summary>
public class ObjectAccessor : Accessor
{
private readonly Hashtable _objectGettersCache, _objectSettersCache;
private readonly Hashtable _objectFieldGettersCache, _objectFieldSettersCache;
[DebuggerStepThrough]
internal ObjectAccessor(IReflect type, bool ignoreCase, bool includeNonPublic)
: base(type, ignoreCase, includeNonPublic)
{
_objectGettersCache = new Hashtable(Properties.Count, Comparer);
_objectSettersCache = new Hashtable(Properties.Count, Comparer);
_objectFieldGettersCache = new Hashtable(Fields.Count, Comparer);
_objectFieldSettersCache = new Hashtable(Fields.Count, Comparer);
//属性
foreach (var pair in Properties)
{
var propName = pair.Key;
var prop = pair.Value;
if (prop.CanRead)
{
_objectGettersCache[propName] = AccessorBuilder.BuildGetter(prop, IncludesNonPublic);
}
if (prop.CanWrite)
{
_objectSettersCache[propName] = AccessorBuilder.BuildSetter(prop, IncludesNonPublic);
}
}
//字段
foreach (var pair in Fields)
{
var propName = pair.Key;
var field = pair.Value;
_objectFieldGettersCache[propName] = AccessorBuilder.BuildGetter(field);
if (!field.IsInitOnly)
{
_objectFieldSettersCache[propName] = AccessorBuilder.BuildSetter(field);
}
}
}
/// <summary>
/// 根据给定的对象和属性[字段]名称对属性[字段]进行读写操作
/// </summary>
public object this[object instance, string propertyOrFieldName]
{
后面还有 31 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
