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
System.IEquatable<CategoryList>
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: 11.20.7
Syntax
public class CategoryList : IComparable, IList<int>, ICollection<int>, IEnumerable<int>, IEnumerable, IReadOnly<CategoryList>, IReadOnly, IModifiedTrackable, IEquatable<CategoryList>
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.

Examples
  Example of enumeration all categories on a page
            foreach (int id in CurrentPage.Category)
    Response.Write("Member of=" + id.ToString());

Constructors

CategoryList()

Initializes a new empty instance of the CategoryList class.

Declaration
public CategoryList()

CategoryList(IEnumerable<Int32>)

Initializes a new instance of the CategoryList class with an initial set of categories.

Declaration
public CategoryList(IEnumerable<int> categories)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Int32> categories

The categories that the CategoryList should be initialized with.

CategoryList(Int32)

Initializes a new instance of the CategoryList class.

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

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

CategoryList(Int32, IEnumerable<Int32>)

Initializes a new instance of the CategoryList class with an initial set of categories.

Declaration
public CategoryList(int categoryType, IEnumerable<int> categories)
Parameters
Type Name Description
System.Int32 categoryType

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

System.Collections.Generic.IEnumerable<System.Int32> categories

The categories that the CategoryList should be initialized with.

Exceptions
Type Condition
System.ArgumentNullException

categories

Properties

CategoryType

Gets the page definition id for this category list.

Declaration
public virtual 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

Gets the number of categories contained in the collection.

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

IsEmpty

Gets a value that indicates if the list contains any categories at all.

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

IsModified

Gets a value indicating whether this CategoryList has been modified after loading.

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

IsReadOnly

Indicates if the current object instance is read-only.

Declaration
public virtual 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 virtual void Add(int category)
Parameters
Type Name Description
System.Int32 category

The category to add.

Clear()

Remove all categories from list.

Declaration
public virtual void Clear()

Contains(Int32)

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

Declaration
public virtual 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 virtual 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(CategoryList)

Declaration
public bool Equals(CategoryList other)
Parameters
Type Name Description
CategoryList other
Returns
Type Description
System.Boolean

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)

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.

MakeReadOnly()

Changes the object instance into a read-only object.

Declaration
public virtual 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 virtual 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(IEnumerable<Int32>)

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

Declaration
public virtual bool MemberOfAll(IEnumerable<int> categories)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Int32> categories

The categories to check.

Returns
Type Description
System.Boolean

True if all categories exists in this CategoryList.

MemberOfAny(IEnumerable<Int32>)

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

Declaration
public virtual bool MemberOfAny(IEnumerable<int> categories)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Int32> categories

The categories to check.

Returns
Type Description
System.Boolean

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

Parse(String)

Parse a string with comma-separated categories to a CategoryList.

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

A comma-separated string with category ids.

Returns
Type Description
CategoryList

Parse(String, Int32)

Parse a string with comma-separated categories to a CategoryList.

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

A comma-separated string with category ids.

System.Int32 categoryType

The category type that the created CategoryList should have

Returns
Type Description
CategoryList

Remove(Int32)

Remove a category from the existing CategoryList.

Declaration
public virtual 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 this CategoryList.

Declaration
public virtual void ResetModified()

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
System.IEquatable<T>

Extension Methods