Class Category
Represents category information that can be associated with IContent instances.
Inheritance
Implements
Inherited Members
Namespace: EPiServer.DataAbstraction
Assembly: EPiServer.dll
Version: 8.11.0Syntax
public class Category : ICloneable, IListSource, IReadOnly<Category>, IReadOnly, IModifiedTrackable
Remarks
Categories are organized in a hierarchical data structure. Each Category instance has a Parent
and a Categories property that can be used to traverse this hierarchy.
You can use one of the FindChild(String) or FindChild(Int32) methods to find
a specific child or descendent category either by Name or ID.
Constructors
Category()
Initializes a new instance of the Category class.
Declaration
public Category()
Category(Category, String)
Initializes a new instance of the Category class.
Declaration
public Category(Category parent, string name)
Parameters
Type | Name | Description |
---|---|---|
Category | parent | The parent of the category. |
System.String | name | The name of the category. |
Category(String, String)
Initializes a new instance of the Category class.
Declaration
public Category(string name, string description)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the category. |
System.String | description | A description of the category. |
Fields
RootName
Name of the root category.
Declaration
public const string RootName = "Root"
Field Value
Type | Description |
---|---|
System.String |
Properties
Available
Gets or sets a value indicating if this Category should be available in edit mode.
Declaration
public virtual bool Available { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Categories
Gets or sets a list of all child categories of this Category.
Declaration
public virtual CategoryCollection Categories { get; set; }
Property Value
Type | Description |
---|---|
CategoryCollection |
Remarks
Note that changes to this collection or to any category contained in this collection must be saved individually by calling the Save(Category) method.
Description
Gets or sets the long description of this Category.
Declaration
public virtual string Description { get; set; }
Property Value
Type | Description |
---|---|
System.String |
GUID
Gets or sets the unique identifier of this Category
Declaration
public virtual Guid GUID { get; set; }
Property Value
Type | Description |
---|---|
System.Guid |
ID
Gets or sets the id of this Category.
Declaration
public virtual int ID { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Indent
Gets or sets the indent of this Category. The indent of the root category is 0.
Declaration
public virtual int Indent { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsModified
Gets a value indicating whether this instance has been modified after loading.
Declaration
public bool IsModified { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsReadOnly
Indicates whether the current object instance is read-only.
Declaration
public virtual bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LocalizationService
Declaration
public LocalizationService LocalizationService { get; set; }
Property Value
Type | Description |
---|---|
LocalizationService |
LocalizedDescription
Gets a localized description of this Category using the LocalizationService. If no localized value is found, the Description will be used.
Declaration
public virtual string LocalizedDescription { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The description field is html encoded if used.
The category description should be localized under the path '/categories/category[@name="MyCategory"]/description' where 'MyCategory' is the name of the current category.
Name
Gets or sets the name of this Category.
Declaration
public virtual string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Parent
Gets or sets the parent category.
This property will be null
for the root category.
Declaration
public virtual Category Parent { get; set; }
Property Value
Type | Description |
---|---|
Category |
Selectable
Gets or sets a value indicating if this Category should be selectable in edit mode
Declaration
public virtual bool Selectable { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
SortOrder
Gets or sets the index for sorting categories on the same branch
Declaration
public virtual int SortOrder { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Clone()
Clone this category and all children to get a new instance
Declaration
[Obsolete("Use CreateWritableClone instead for similar functionality.")]
public object Clone()
Returns
Type | Description |
---|---|
System.Object | A new identical category derived from the current |
CreateWritableClone()
Creates a writable copy of the current and all descendant categories.
Declaration
public virtual Category CreateWritableClone()
Returns
Type | Description |
---|---|
Category | A writable copy of the current Category. |
Remarks
The cloning is a deep-copy except for the Parent property that is preserved on the returned Category. The writable status of the parent instance will not be changed.
Delete()
Delete the current category and its children from the collection and database
Declaration
[Obsolete("Use CategoryRepository.Delete instead.")]
public void Delete()
Find(Int32)
Recursive search for a category starting at the root
Declaration
[Obsolete("Use CategoryRepository.Get instead.")]
public static Category Find(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | The id number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
Find(String)
Recursive search for a category starting at the root
Declaration
[Obsolete("Use CategoryRepository.Get instead.")]
public static Category Find(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
FindChild(Int32)
Recursive search for a category in all descendant children
Declaration
public virtual Category FindChild(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | The id number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
FindChild(String)
Recursive search for a category in all descendant children
Declaration
public virtual Category FindChild(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
Remarks
The search is not case-sensitive (uses OrdinalIgnoreCase).
GetList()
Gets a list of all descendant categories.
Declaration
public IList GetList()
Returns
Type | Description |
---|---|
System.Collections.IList |
Remarks
Implements IListSource which provides the functionality so a category tree can be databound as a flat list.
GetRoot()
Get the category tree starting at the root
Declaration
[Obsolete("Use CategoryRepository.GetRoot instead.")]
public static Category GetRoot()
Returns
Type | Description |
---|---|
Category | The root category |
MakeReadOnly()
Changes the object instance into a read-only object.
Declaration
public void MakeReadOnly()
Remarks
After calling this method, any attempt to change the object instance or any contained object will generate a System.NotSupportedException. I.e. the semantics is "deep read-only".
Note! After setting an object to read-only it is not possible to revert back to read-write mode. You will have to call the CreateWritableClone method to get a copy that can be modified.
ResetModified()
Resets the modified flag on all the data contained on the instance.
Declaration
public virtual void ResetModified()
Save()
Save changes made to the current category
Declaration
[Obsolete("Use CategoryRepository.Save instead.")]
public void Save()
Remarks
Will only save changes to the current category and not child categories
ThrowIfReadOnly()
Throws an exception if the current instance is read-only.
Declaration
protected void ThrowIfReadOnly()
Explicit Interface Implementations
IReadOnly.CreateWritableClone()
Declaration
object IReadOnly.CreateWritableClone()
Returns
Type | Description |
---|---|
System.Object |