using System;
using System.CodeDom;
using System.Reflection;
namespace Chernobyl.Reflection.Template.CodeDom
{
///
/// An that can take any
/// instance that represents a property and generate CodeDom for it.
///
public class CodeDomProperty : CodeDomAssignableMember
{
///
/// Initializes a new instance of the class.
///
/// The instance to
/// generate CodeDom for and provide the
/// implementation for this class.
/// Thrown if the member is not
/// a property. In other words, the
/// on the is not equal to
/// .
public CodeDomProperty(IMember member) : base(member)
{
if(Info.MemberType != MemberTypes.Property)
throw new ArgumentException("The member must be a property.", "member");
}
///
/// The reference to the assignable member as a code expression. This
/// reference will be used to generate code that can set the member.
/// The reference to the property assumes the target object is
/// .
///
public override CodeExpression AssignableMemberReference
{
get { return _assignableMemberReference; }
}
///
/// Initializes the .
/// Note to implementers: Base classes should invoke the base class
/// method when their
/// is initialized.
///
protected override void Configure()
{
// note that we don't configure the AssignableMemberReference if our
// Parent is not set to a CodeDomInstance because the property
// TheGenericInstancePropertyReference uses the CodeDomInstance
// Parent reference to generate the required code.
if (Parent != null && Parent is CodeDomInstance && _assignableMemberReference == null)
{
_assignableMemberReference =
new CodePropertyReferenceExpression(TheGenericInstancePropertyReference, Name);
base.Configure();
}
}
///
/// The backing field to .
///
CodeExpression _assignableMemberReference;
}
}