using System;
using System.Reflection;
namespace ShwasherSys.ReflectionMagic
{
///
/// Provides a mechanism to access fields through the abstraction.
///
internal class Field : IProperty
{
private readonly FieldInfo _fieldInfo;
///
/// Initializes a new instance of the class wrapping the specified field.
///
/// The field info to wrap.
/// Thrown when is null.
internal Field(FieldInfo field)
{
if (field == null)
throw new ArgumentNullException(nameof(field));
_fieldInfo = field;
}
public Type PropertyType => _fieldInfo.FieldType;
string IProperty.Name => _fieldInfo.Name;
object IProperty.GetValue(object obj, object[] index)
{
return _fieldInfo.GetValue(obj);
}
void IProperty.SetValue(object obj, object value, object[] index)
{
_fieldInfo.SetValue(obj, value);
}
}
[Obsolete("Will be made internal in a future release.")]
public static class FieldInfoExtensions
{
[Obsolete("This is an internal API. If you are using this consider opening an issue on GitHub.")]
public static IProperty ToIProperty(this FieldInfo info)
{
return new Field(info);
}
}
}