Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Extending <strong>EPiServer</strong> Community | 123<br />
3 Extending <strong>EPiServer</strong> Community<br />
3.1 Extending <strong>EPiServer</strong> Community classes<br />
This tutorial describes howto create a derived class with custom attributes, and that exposes those attributes as fixed<br />
properties in the derived class. This is in many cases a more elegant approach than accessing the attributes directly via<br />
the attribute name.<br />
In this tutorial we assume that we have a community implementation that requires the EntryComment class in Blog to<br />
have an ImageGallery connected to it, where users can upload pictures when commenting an Entry. One way of<br />
accomplishing this would of course be to just add an attribute to the EntryComment as described in section 2.5 and be<br />
done with it. However, there is a more elegant way to use attributes without the need of keeping track of the attribute<br />
names in your ASP.NET page.<br />
We start by creating a new class derived from EntryComment.<br />
using System.Collections.Generic;<br />
using StarCommunity.Modules.Blog;<br />
using StarCommunity.Modules.ImageGallery;<br />
namespaceMyCommunity<br />
{<br />
//Inherit the EntryComment class<br />
public class MyEntryComment : EntryComment<br />
{<br />
// The constructor takes DbDataReader and passes it to base class<br />
public MyEntryComment(DbDataReader reader) : base(reader) { }<br />
// Define the ImageGallery property for get and set<br />
public ImageGallery ImageGallery<br />
{<br />
get{return this.getAttributeValue("attr_ig");}<br />
set{blog.entity.SetAttributeValue("attr_ig",value));}<br />
}<br />
}<br />
}<br />
© <strong>EPiServer</strong> AB