The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
This article is really more on C# generics, however we will examine some of the principles and see how can we apply them on the Views hierarchy. Namely, we know that every time we declare a View (be it ViewModeControl or ViewModeUserControl) we define the host of the control as a generic type of that class. An example of the View declaration looks like this:
public class BlogsListView : ViewModeControl<BlogsView> |
However, there are cases when we don’t wish to hard code the host (or parent) of the View. Namely, as we will see in the articles on “Designing reusable Views” and “Host ambivalence”, sometimes it is opportune to develop Views which can be reused in different modules and in different places of the hierarchy. The key to this approach is not to hard code the host, but rather make it generic. Generic Content module, which is largely reused throughout Sitefinity, is a great example of such design. Let us take a look at the View declaration of one of the Generic Content module Views.
public class ContentItemEdit<THost> : ViewModeControl<THost> where THost : Control, IGenericContentHost |
public class NewsItemEdit : ContentItemEdit<NewsItemsView> |
/// <summary> |
/// Defines the members that each host in Generic Content module needs |
/// to implement |
/// </summary> |
public interface IGenericContentHost |
{ |
/// <summary> |
/// Content Manager used by the control |
/// </summary> |
ContentManager Manager { get; } |
/// <summary> |
/// Gets the mode key for the host control |
/// </summary> |
string ViewModeKey { get; } |
/// <summary> |
/// Gets parameter key for the host control |
/// </summary> |
string ParameterKey { get; } |
/// <summary> |
/// Gets the type of the view mode. |
/// </summary> |
/// <value>The type of the view mode.</value> |
Type ViewModeType { get; } |
} |
This, finally, allows us to access these properties through the this.Host property from the ContentEditView, even though we don’t know what the host of the View will be. Therefore, we have created a host agnostic View, which is however, specialized for the Generic Content based modules.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.