Class CategoryList
Datatype for categories. Used to classify pages with system-wide categories.
Inheritance
Implements
Inherited Members
Namespace: EPiServer.Core
Assembly: EPiServer.dll
Version: 9.12.2Syntax
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(PageData)
Create a new category list and initialize it from category data on a page.
Declaration
[Obsolete("Create list manually passing in the page category value to other constructor.")]
public CategoryList(PageData pageData)
Parameters
Type | Name | Description |
---|---|---|
PageData | pageData | The PageData with categories. |
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 |
CategoryList(String)
Create a new category list and initialize it from the string.
Declaration
[Obsolete("Use CategoryList.Parse instead.")]
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
[Obsolete("Use CategoryList.Parse instead.")]
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 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 |
|
Overrides
GetCategoryName(Int32)
Look up the name of a category.
Declaration
[Obsolete("Use CategoryRepository.Get() to load individual categories by id and retrieve their name.")]
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
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
[Obsolete("Use CategoryRepository.GetRoot().List() instead to get all categories")]
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 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 |
ParseCategories(PageData)
Parses categories based on values from another page.
Declaration
[Obsolete("Parse categories manually passing in the page category value to other method.")]
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
[Obsolete("Use CategoryList.Parse instead.")]
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 virtual bool Remove(int category)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | category | The category to remove. |
Returns
Type | Description |
---|---|
System.Boolean |
|
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()
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
[Obsolete("Use CategoryRepository.Get() to load individual categories by name.")]
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
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 |