Try our conversational search powered by Generative AI!

Class CategoryList

Datatype for categories. Used to classify pages with system-wide categories.

Inheritance
System.Object
CategoryList
Implements
System.IComparable
System.Collections.Generic.IList<System.Int32>
System.Collections.Generic.ICollection<System.Int32>
System.Collections.Generic.IEnumerable<System.Int32>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Core
Assembly: EPiServer.dll
Version: 7.19.2
Syntax
public class CategoryList : IComparable, IList<int>, ICollection<int>, IEnumerable<int>, IEnumerable, IReadOnly<CategoryList>, IReadOnly, IModifiedTrackable
Remarks

CategoryList is a lightweight collection of System.Int32 values pointing to categories. Used primarily from the Category property on PageData class which holds page information.

If you need to populate a category list based on names, there is a helper method: ResolveCategoryNames(String).

Examples

Example of enumeration all categories on a page

Constructors

CategoryList()

Create a new, empty category list.

Declaration
public CategoryList()

CategoryList(PageData)

Create a new category list and initialize it from category data on a page.

Declaration
public CategoryList(PageData pageData)
Parameters
Type Name Description
PageData pageData

The PageData with categories.

CategoryList(Int32)

Initializes a new instance of the CategoryList class.

Declaration
public CategoryList(int categoryType)
Parameters
Type Name Description
System.Int32 categoryType

The page definition id of the category or 0 if it's the built in page categories.

CategoryList(Int32[])

Create a new category list with categories initialized from the array.

Declaration
public CategoryList(int[] categories)
Parameters
Type Name Description
System.Int32[] categories

The array of categories.

Remarks

Note that the array is copied so it can be manipulated after calling this constructor without causing side-effects in the CategoryList.

CategoryList(String)

Create a new category list and initialize it from the string.

Declaration
public CategoryList(string complexReference)
Parameters
Type Name Description
System.String complexReference

The string with categories.

Remarks

The format of the initialization string is assumed to be a comma-separated list of integers, i e "3,45,76,89".

If a value cannot be parsed as an integer, a System.FormatException is thrown.

CategoryList(String, Int32)

Create a new category list and initialize it from the string.

Declaration
public CategoryList(string complexReference, int categoryType)
Parameters
Type Name Description
System.String complexReference

The string with categories.

System.Int32 categoryType

The type of category list, i e then generic page catgeory (categoryType = 0) or a specific categrory property (categoryType = page definition type if)

Remarks

The format of the initialization string is assumed to be a comma-separated list of integers, i e "3,45,76,89".

If a value cannot be parsed as an integer, a System.FormatException is thrown.

Properties

CategoryType

Gets the page definition id for this category list.

Declaration
public int CategoryType { get; }
Property Value
Type Description
System.Int32

The page definition id of the category.

Remarks

Returns 0 for built in page categories.

Count

The number of categories contained in the collection.

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32

IsEmpty

Determine if the list contains any categories at all.

Declaration
public bool IsEmpty { get; }
Property Value
Type Description
System.Boolean

IsModified

Checks if categories have been modified since last load.

Declaration
public bool IsModified { get; set; }
Property Value
Type Description
System.Boolean

IsReadOnly

Indicates if the current object instance is read-only.

Declaration
public bool IsReadOnly { get; }
Property Value
Type Description
System.Boolean

True if the current object instance is read-only; otherwise false.

Item[Int32]

Gets the item at the specified index.

Declaration
public int this[int index] { get; set; }
Parameters
Type Name Description
System.Int32 index
Property Value
Type Description
System.Int32

The item at the specified index.

Methods

Add(Int32)

Add a category to the existing CategoryList.

Declaration
public void Add(int category)
Parameters
Type Name Description
System.Int32 category

The category to add.

Clear()

Remove all categories from list.

Declaration
public void Clear()

Contains(Int32)

/// Determines whether an element is in the list.

Declaration
public bool Contains(int category)
Parameters
Type Name Description
System.Int32 category

The item

Returns
Type Description
System.Boolean

true if item is found in the list; otherwise, false.

Copy()

Copies this instance.

Declaration
public CategoryList Copy()
Returns
Type Description
CategoryList

A new instance of CategoryList with the values from the current instance.

CopyTo(Int32[], Int32)

Copies the entire list to a compatible one-dimensional array, starting at the specified index of the target array.

Declaration
public void CopyTo(int[] array, int arrayIndex)
Parameters
Type Name Description
System.Int32[] array

The one-dimensional System.Array that is the destination of the elements copied from list. The System.Array must have zero-based indexing.

System.Int32 arrayIndex

The zero-based index in array at which copying begins.

CreateWritableClone()

Create a copy of the current object instance that is writable.

Declaration
public CategoryList CreateWritableClone()
Returns
Type Description
CategoryList

A new copy of the object.

Remarks

The cloning is a deep-copy.

Equals(Object)

Determines whether the specified System.Object is equal to this instance.

Declaration
public override bool Equals(object o)
Parameters
Type Name Description
System.Object o

The System.Object to compare with this instance.

Returns
Type Description
System.Boolean

true if the specified System.Object is equal to this instance; otherwise, false.

Overrides
System.Object.Equals(System.Object)

GetCategoryName(Int32)

Look up the name of a category.

Declaration
public string GetCategoryName(int categoryID)
Parameters
Type Name Description
System.Int32 categoryID

Category ID of the category

Returns
Type Description
System.String

The category name. If category ID can not be found an empty string is returned.

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration
public IEnumerator<int> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<System.Int32>

A System.Collections.Generic.IEnumerator<T> that can be used to iterate through the collection.

GetHashCode()

Returns a hash code for this instance.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Overrides
System.Object.GetHashCode()

IndexOf(Int32)

Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the list that starts at the specified index and contains the specified number of elements.

Declaration
public int IndexOf(int item)
Parameters
Type Name Description
System.Int32 item

The item.

Returns
Type Description
System.Int32

The zero-based index of the first occurrence of item within the range of elements in the list that extends from index to the last element, if found; otherwise, –1.

Insert(Int32, Int32)

Inserts an element into the Slist at the specified index.

Declaration
public void Insert(int index, int item)
Parameters
Type Name Description
System.Int32 index

The index.

System.Int32 item

The item.

LoadCategories()

Loads all categories into a new CategoryList object.

Declaration
public static CategoryList LoadCategories()
Returns
Type Description
CategoryList

CategoryList object with all categories

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.

MemberOf(Int32)

Checks if this CategoryList belongs to a specific category.

Declaration
public bool MemberOf(int category)
Parameters
Type Name Description
System.Int32 category

The category (int) to check.

Returns
Type Description
System.Boolean

True if the category is a member of this CategoryList

MemberOfAll(CategoryList)

Checks if this instance contains all the categories in the specified CategoryList.

Declaration
public bool MemberOfAll(CategoryList categories)
Parameters
Type Name Description
CategoryList categories

The categories to check against.

Returns
Type Description
System.Boolean

True if this instance contains all the categories in the specified CategoryList; otherwise false.

MemberOfAll(Int32[])

Check if all categories in the provided list exist in this CategoryList.

Declaration
public bool MemberOfAll(int[] categories)
Parameters
Type Name Description
System.Int32[] categories

The categories to check.

Returns
Type Description
System.Boolean

True if all categories exists in this CategoryList.

MemberOfAny(CategoryList)

Checks if any of the categories provided in the list exist in this CategoryList.

Declaration
public bool MemberOfAny(CategoryList categories)
Parameters
Type Name Description
CategoryList categories

The categories to check.

Returns
Type Description
System.Boolean

True if at least one of the categories exist in this CategoryList.

MemberOfAny(Int32[])

Checks if any of the categories provided in the list exist in this CategoryList.

Declaration
public bool MemberOfAny(int[] categories)
Parameters
Type Name Description
System.Int32[] categories

The categories to check.

Returns
Type Description
System.Boolean

True if at least one of the categories exist in this CategoryList.

ParseCategories(PageData)

Parses categories based on values from another page.

Declaration
public void ParseCategories(PageData pageData)
Parameters
Type Name Description
PageData pageData
Remarks

This method actually takes a copy of the other page categories and inserts them in the local collection.

ParseCategories(String)

Parse a string with comma-separated categories.

Declaration
public void ParseCategories(string complexReference)
Parameters
Type Name Description
System.String complexReference

The string with categories.

Remove(Int32)

Remove a category from the existing CategoryList.

Declaration
public bool Remove(int category)
Parameters
Type Name Description
System.Int32 category

The category to remove.

Returns
Type Description
System.Boolean

true if success; otherwise false

RemoveAt(Int32)

Removes the link at the specified index.

Declaration
public void RemoveAt(int index)
Parameters
Type Name Description
System.Int32 index

The index.

ResetModified()

Resets the modified flag on all the data contained on the instance.

Declaration
public void ResetModified()

ResolveCategoryNames(String)

Resolves a list of category names and translates the names to category IDs. The contents of the CategoryList object are replaced with the new list. All category names must exist in the database, otherwise an exception is thrown.

Declaration
public void ResolveCategoryNames(string complexNameList)
Parameters
Type Name Description
System.String complexNameList

Comma-separated list of category names, for eg. "technical,news,products"

ThrowIfReadOnly()

Throws an System.NotSupportedException if this instance is set to read only.

Declaration
protected void ThrowIfReadOnly()

ToString()

Returns a comma separated System.String that represents this instance.

Declaration
public override string ToString()
Returns
Type Description
System.String

A comma separated System.String that represents this instance.

Overrides
System.Object.ToString()

Operators

Equality(CategoryList, CategoryList)

Implements the operator == to compare two CategoryList instances.

Declaration
public static bool operator ==(CategoryList x, CategoryList y)
Parameters
Type Name Description
CategoryList x

The first CategoryList.

CategoryList y

The second CategoryList.

Returns
Type Description
System.Boolean

The result of the operator.

Inequality(CategoryList, CategoryList)

Implements the operator != to compare two CategoryList instances..

Declaration
public static bool operator !=(CategoryList x, CategoryList y)
Parameters
Type Name Description
CategoryList x

The first CategoryList.

CategoryList y

The second CategoryList.

Returns
Type Description
System.Boolean

The result of the operator.

Explicit Interface Implementations

IReadOnly.CreateWritableClone()

Creates writable clone of this object.

Declaration
object IReadOnly.CreateWritableClone()
Returns
Type Description
System.Object

Writable clone object.

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

An System.Collections.IEnumerator object that can be used to iterate through the collection.

IComparable.CompareTo(Object)

Declaration
int IComparable.CompareTo(object x)
Parameters
Type Name Description
System.Object x
Returns
Type Description
System.Int32

Implements

System.IComparable
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable

Extension Methods