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