using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Reflection; namespace ShwasherSys.ReflectionMagic { public class DynamicObjectInstance : DynamicObjectBase { private static readonly ConcurrentDictionary> _propertiesOnType = new ConcurrentDictionary>(); private readonly object _instance; /// /// Initializes a new instance of the class, wrapping the specified object. /// /// The object to wrap. /// Thrown when is null. public DynamicObjectInstance(object instance) { _instance = instance ?? throw new ArgumentNullException(nameof(instance)); } protected override IDictionary> PropertiesOnType => _propertiesOnType; // For instance calls, we get the type from the instance protected override Type TargetType => _instance.GetType(); protected override object Instance => _instance; public override object RealObject => Instance; protected override BindingFlags BindingFlags => BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; } }