ContextualFieldInfo
A field info with contextual information.
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Namotion.Reflection
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class ContextualFieldInfo : ContextualAccessorInfo
{
[System.Runtime.CompilerServices.Nullable(2)]
private string _name;
public FieldInfo FieldInfo { get; }
public override MemberInfo MemberInfo => FieldInfo;
public override ContextualType AccessorType => FieldType;
public ContextualType FieldType { get; set; }
public override string Name => _name ?? (_name = FieldInfo.Name);
internal ContextualFieldInfo(FieldInfo fieldInfo, ref int nullableFlagsIndex, [System.Runtime.CompilerServices.Nullable(2)] byte[] nullableFlags)
{
FieldInfo = fieldInfo;
FieldType = new ContextualType(fieldInfo.FieldType, fieldInfo.GetCustomAttributes(true).OfType<Attribute>().ToArray(), null, ref nullableFlagsIndex, nullableFlags, (!fieldInfo.DeclaringType.IsNested) ? new object[2] {
fieldInfo.DeclaringType,
fieldInfo.DeclaringType.GetTypeInfo().Assembly
} : new object[3] {
fieldInfo.DeclaringType,
fieldInfo.DeclaringType.DeclaringType,
fieldInfo.DeclaringType.GetTypeInfo().Assembly
});
}
[System.Runtime.CompilerServices.NullableContext(2)]
public override object GetValue(object obj)
{
return FieldInfo.GetValue(obj);
}
[System.Runtime.CompilerServices.NullableContext(2)]
public override void SetValue(object obj, object value)
{
FieldInfo.SetValue(obj, value);
}
}
}