using System;
using System.Reflection;
namespace Chernobyl.Reflection.Template
{
///
/// An that allows for at runtime switching of
/// it's implementation and makes creating new s
/// easier through the use of other implementations.
///
public abstract class InstanceDecorator : ComponentDecorator, IInstance
{
///
/// Initializes a new instance of the class.
/// Note to implementors: this constructor immediately configures the
/// using the
/// method. This
/// assumes the is ready to use.
///
protected InstanceDecorator()
: this(true)
{ }
///
/// Initializes a new instance of the class.
///
/// True if this instance should be configured
/// immediately, false if the
/// method will be
/// invoked at a later time by the implementing type.
protected InstanceDecorator(bool configure) : base(configure)
{ }
///
/// The object that this represents. If the object
/// has not yet been created, then the will not
/// create the object until this property is called.
///
public object TheInstance
{
get { return DecoratedInstance.TheInstance; }
set { DecoratedInstance.TheInstance = value; }
}
///
/// The name of the assembly where this instance is located.
///
public virtual AssemblyName Assembly
{
get { return DecoratedInstance.Assembly; }
}
///
/// The type of this instance.
///
public virtual Type Type
{
get { return DecoratedInstance.Type; }
}
///
/// True if the property has been set, false
/// if otherwise.
///
public bool IsReady
{
get { return DecoratedInstance.IsReady; }
}
///
/// An event that is thrown right after the
/// property has been set. If an event handler is assigned to this event
/// after it has become ready, then that event handler will be
/// immediately invoked.
///
public event EventHandler BecameReady
{
add { DecoratedInstance.BecameReady += value; }
remove { DecoratedInstance.BecameReady -= value; }
}
///
/// The instance that implements the
/// functionality of this class.
///
protected override IComponent DecoratedComponent
{
get { return DecoratedInstance; }
}
///
/// The instance that implements the
/// functionality of this class.
///
public abstract IInstance DecoratedInstance { get; }
}
}