<PackageReference Include="Namotion.Reflection" Version="3.4.2" />

ContextualFieldInfo

A field info with contextual information.
using System; 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; NullableFlagsSource[] customAttributeProviders = (!fieldInfo.DeclaringType.IsNested) ? new NullableFlagsSource[1] { NullableFlagsSource.Create(fieldInfo.DeclaringType, fieldInfo.DeclaringType.GetTypeInfo().Assembly) } : new NullableFlagsSource[2] { NullableFlagsSource.Create(fieldInfo.DeclaringType, null), NullableFlagsSource.Create(fieldInfo.DeclaringType.DeclaringType, fieldInfo.DeclaringType.GetTypeInfo().Assembly) }; FieldType = new ContextualType(fieldInfo.FieldType, this, null, ref nullableFlagsIndex, nullableFlags, customAttributeProviders); } [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); } public override object[] GetCustomAttributes(Type attributeType, bool inherit) { return FieldInfo.GetCustomAttributes(attributeType, inherit); } public override object[] GetCustomAttributes(bool inherit) { return FieldInfo.GetCustomAttributes(inherit); } public override bool IsDefined(Type attributeType, bool inherit) { return FieldInfo.IsDefined(attributeType, inherit); } } }