Do you have actual classes that represent the views? If so, then I'd use the Type to describe the views. Then you can have the RegisterExplorerComponent method accept the Type or, if you are instantiating the Views, the base class or interface used by the Views.
Another option would be to use a class rather than an enumeration to define the various views. Each view can be defined as a read-only property on the class. Then you can derive this class to extend it with additional views. Since your RegisterExplorerComponent method accepts the base type, it will accept the derived class as well.
Not knowing your full use-case, here is an example of how I've implemented something similar:
public class ViewDefinition
perfect - for the most part I have actual classes that
match the views but I'm using the same enum for multiple purposes. ie) enum.SomethingDetailView
would be used for the readonly or the edit or the list version just depending
on the use. The example you laid out is exactly what I needed. I
basically wanted an inheritable enum which is easily represented with a class.
thanks.
jack
From: SonOfPirate [mailto:cslanet@lhotka.net]
Sent: May-27-09 4:33 PM
To: jaddington@alexandergracie.com
Subject: Re: [CSLA .NET] OT: Design Help
Do you have actual classes that represent the views? If so, then I'd
use the Type to describe the views. Then you can have the
RegisterExplorerComponent method accept the Type or, if you are instantiating
the Views, the base class or interface used by the Views.
Another option would be to use a class rather than an enumeration to define
the various views. Each view can be defined as a read-only property on
the class. Then you can derive this class to extend it with additional
views. Since your RegisterExplorerComponent method accepts the base type,
it will accept the derived class as well.
Not knowing your full use-case, here is an example of how I've implemented
something similar:
public class ViewDefinition
{
internal ViewDefinition(System.String name)
{
Name = name;
}
public System.String Name
{
get;
private
set;
}
}
public abstract class MasterViews
{
public static readonly ViewDefinition View1 = new
ViewDefinition("View1");
public static readonly ViewDefinition View2 = new
ViewDefinition("View2");
}
public class CustomViews : MasterViews
{
public static readonly ViewDefinition NewView1 = new
ViewDefinition("NewView1");
public static readonly ViewDefinition NewView2 = new
ViewDefinition("NewView2");
}
public abstract class AbstractBaseClass
{
protected
AbstractBaseClass()
{
Initialize();
}
protected virtual void Initialize()
{
RegisterExplorerComponents(MasterViews.View1);
RegisterExplorerComponents(MasterViews.View2);
}
protected void
RegisterExplorerComponents(ViewDefinition
view)
{
// ...
}
}
public class DerivedClass : AbstractBaseClass
{
public DerivedClass() : base()
{ }
protected override void Initialize()
{
RegisterExplorerComponents(CustomViews.View1);
RegisterExplorerComponents(CustomViews.View2);
}
}
Copyright (c) Marimer LLC