Class ContentReference
Contains information to reference ContentData instances.
Implements
Inherited Members
Namespace: EPiServer.Core
Assembly: EPiServer.dll
Version: 9.12.2Syntax
public class ContentReference : IComparable, IReadOnly<ContentReference>, IReadOnly, IComparable<ContentReference>, IEquatable<ContentReference>
Constructors
ContentReference()
Initializes a new instance of the ContentReference class.
Declaration
public ContentReference()
ContentReference(Int32)
Initialize a new ContentReference with content id.
Declaration
public ContentReference(int contentID)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentID | The content ID. |
ContentReference(Int32, Boolean)
Initialize a new ContentReference with content id and any available version. If no version is published the most recently saved will be loaded.
Declaration
public ContentReference(int contentID, bool getPublishedOrLatest)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentID | The content id to set |
System.Boolean | getPublishedOrLatest | If the most recently saved should be loaded if no version is published. |
ContentReference(Int32, Int32)
Initialize a new ContentReference with content id and working version.
Declaration
public ContentReference(int contentID, int versionID)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentID | The content ID. |
System.Int32 | versionID | The version ID. |
ContentReference(Int32, Int32, String)
Initialize a new ContentReference with content id, working version and providerName.
Declaration
public ContentReference(int contentID, int versionID, string providerName)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentID | The content id to set |
System.Int32 | versionID | The version to set |
System.String | providerName | The name of the provider |
ContentReference(Int32, Int32, String, Boolean)
Initialize a new ContentReference with content id, working version and remote site.
Declaration
public ContentReference(int contentID, int versionID, string providerName, bool getPublishedOrLatest)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentID | The content ID to set. |
System.Int32 | versionID | The version ID to set. |
System.String | providerName | Name of the provider. |
System.Boolean | getPublishedOrLatest | This parameter is not used, see remarks |
ContentReference(Int32, String)
Initialize a new ContentReference with content id and providerName.
Declaration
public ContentReference(int contentID, string providerName)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentID | The content id to set |
System.String | providerName | Name of the provider. |
ContentReference(String)
Initialize a new ContentReference from a string in the format contentID[_workID[_providerName]] or - throws EPiServerException on invalid argument
Declaration
public ContentReference(string complexReference)
Parameters
Type | Name | Description |
---|---|---|
System.String | complexReference | The string containing content information |
Exceptions
Type | Condition |
---|---|
EPiServerException | Thrown if the string cannot be parsed as a valid ContentReference. |
Fields
EmptyReference
Returns an empty ContentReference.
Declaration
public static readonly ContentReference EmptyReference
Field Value
Type | Description |
---|---|
ContentReference |
SelfReference
Returns a ContentReference that references the current Content.
Declaration
public static readonly ContentReference SelfReference
Field Value
Type | Description |
---|---|
ContentReference |
Properties
GetPublishedOrLatest
Indicates if the ContentReference references a specific version or may be used to load the latest version.
Declaration
public bool GetPublishedOrLatest { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
This property only returns true
if the ContentReference object was created via the ContentReference(Int32, Boolean)
constructor. Typically, that constructor is used when you want to load the latest version a ContentData regardless if it's
published or not.
When GetPublishedOrLatest is set then the loading will not take fallback or replacement language settings into account.
When a ContentReference with GetPublishedOrLatest is set to true
is passed to IContentLoader
the returned IContent object will be, in order of preference:
If GetPublishedOrLatest is set to true
, any value assigned to WorkID will be ignored.
This setting is mainly used internally from edit of content and should be used with care since it might bypass cache.
GlobalBlockFolder
Gets or sets the global block folder.
Declaration
public static ContentReference GlobalBlockFolder { get; set; }
Property Value
Type | Description |
---|---|
ContentReference |
ID
The id number of a ContentData instance.
Declaration
public int ID { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
The content ID is a database assigned number and the only function is to provide a unique identification of a content instance within the current site.
IsExternalProvider
Check if this reference is towards an external content provider.
Declaration
public bool IsExternalProvider { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if it is a content provider. |
Remarks
A ContentReference can point to an external provider as indicated by the ProviderName property.
IsReadOnly
Indicates if the ContentReference is read-only.
Declaration
public bool IsReadOnly { get; protected set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ProviderName
A string that identifies a a provider that serves the content. For content served by default provider this value is null.
Declaration
public string ProviderName { get; set; }
Property Value
Type | Description |
---|---|
System.String | True if it is a extern reference. |
Remarks
To see if the ContentReference is extern, use the IsExternProvider method rather than looking at the ProviderName.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown if the instance is read-only. |
RootPage
Gets a PageReference to the root page.
Declaration
public static PageReference RootPage { get; set; }
Property Value
Type | Description |
---|---|
PageReference | The root page. |
Remarks
This property is null until the application has been initialized.
SiteBlockFolder
Gets or sets the site specific block folder.
Declaration
public static ContentReference SiteBlockFolder { get; set; }
Property Value
Type | Description |
---|---|
ContentReference |
StartPage
Gets a PageReference to the start page.
Declaration
public static PageReference StartPage { get; set; }
Property Value
Type | Description |
---|---|
PageReference |
WasteBasket
Gets a PageReference to the wastebasket page.
Declaration
public static PageReference WasteBasket { get; set; }
Property Value
Type | Description |
---|---|
PageReference |
Remarks
This property is null until the application has been initialized.
WorkID
The version id of a ContentData instance.
Declaration
public int WorkID { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
This is an internal representation of ContentData versions. I e it is not a sequential version number for the content, but can contain any value. The only guarantee is that if content version A is created before content version B, then A.WorkID < B.WorkID
Methods
CompareTo(ContentReference)
Compares the instance to another provided ContentReference.
Declaration
public virtual int CompareTo(ContentReference other)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | other | The other ContentReference instance to compare against. |
Returns
Type | Description |
---|---|
System.Int32 | Zero if both instances are considered equal, Greater than zero if this instance is greater than the provided, Less than zero if the provided instance is greater than this instance. |
CompareTo(Object)
Compares the instance to the given object.
Declaration
public virtual int CompareTo(object x)
Parameters
Type | Name | Description |
---|---|---|
System.Object | x | The object to compare against. |
Returns
Type | Description |
---|---|
System.Int32 | Zero if both instances are considered equal, Greater than zero if this instance is greater than the provided, Less than zero if the provided instance is greater than this instance. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if x is not of type ContentReference. |
CompareToIgnoreWorkID(ContentReference)
Compares two ContentReference but ignores WorkID.
Declaration
public virtual bool CompareToIgnoreWorkID(ContentReference contentReference)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentReference | The content reference. |
Returns
Type | Description |
---|---|
System.Boolean | Will return true if ID and ProviderName are the same, otherwise false. |
Copy()
Declaration
public ContentReference Copy()
Returns
Type | Description |
---|---|
ContentReference |
CreateReferenceWithoutVersion()
Creates a reference to published content, that is a ContentReference with WorkID=0.
Declaration
[Obsolete("This method has performance implications since it always clones objects, use ToReferenceWithoutVersion extension method instead")]
public ContentReference CreateReferenceWithoutVersion()
Returns
Type | Description |
---|---|
ContentReference |
CreateWritableClone()
Creates a writable copy of the current ContentReference instance.
Declaration
public ContentReference CreateWritableClone()
Returns
Type | Description |
---|---|
ContentReference | A writable copy of the current ContentReference instance. |
Equals(ContentReference)
Indicates whether the current ContentReference is equal to another ContentReference.
Declaration
public virtual bool Equals(ContentReference other)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | other | A ContentReference to compare with this object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current object is equal to the |
Equals(ContentReference, Boolean)
Indicates whether the current ContentReference is equal to another ContentReference.
Declaration
public virtual bool Equals(ContentReference other, bool ignoreVersion)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | other | A ContentReference to compare with this object. |
System.Boolean | ignoreVersion | Indicates if version information should be excluded from the comparison. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current object is considered equal to the |
Equals(Object)
Returns true if the objects o is equal with the instance of the ContentReference.
Declaration
public override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
System.Object | o | The o. |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
GetHashCode()
Serves as a hash function for a particular type.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A hash code for the current System.Object. |
Overrides
IsNullOrEmpty(ContentReference)
Determines whether the specified content link is null or empty.
Declaration
public static bool IsNullOrEmpty(ContentReference contentLink)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentLink | The content link. |
Returns
Type | Description |
---|---|
System.Boolean |
|
MakeReadOnly()
Changes the ContentReference into a read-only object.
Declaration
public virtual void MakeReadOnly()
Remarks
After calling this method, any attempt to modify this 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.
Parse(String)
Parses the specified string to a ContentReference instance.
Declaration
public static ContentReference Parse(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string that should be parsed. |
Returns
Type | Description |
---|---|
ContentReference | A ContentReference instance if the string could be parsed; otherwise an exception in thrown. |
ParseReference(String)
Create a new instance of type inheriting from ContentReference from a string representation.
Declaration
[Obsolete("Use TryParse or Parse methods instead.")]
public virtual ContentReference ParseReference(string complexReference)
Parameters
Type | Name | Description |
---|---|---|
System.String | complexReference | The string representation. |
Returns
Type | Description |
---|---|
ContentReference | The created instance. |
ThrowIfReadOnly()
Utility method that, when called, throws a System.NotSupportedException indicating that the ContentReference has been set as read-only.
Declaration
protected void ThrowIfReadOnly()
Remarks
This method is used internally by other ContentReference methods to standardize the exception thrown when trying to modify a ContentReference set as read-only.
ToString()
Returns a System.String that represents the current System.Object. The return value can be be a string like "Digit[_Digit[_String]]" or "-"
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A System.String that represents the current System.Object. The ContentReference format can be a string like "Digit[_Digit[_String]]", "-" or String.Empty |
Overrides
TryParse(String, out ContentReference)
Tries the parse.
Declaration
public static bool TryParse(string complexReference, out ContentReference result)
Parameters
Type | Name | Description |
---|---|---|
System.String | complexReference | The complex reference. |
ContentReference | result | The result. |
Returns
Type | Description |
---|---|
System.Boolean |
Operators
Equality(ContentReference, ContentReference)
Implements the operator ==.
Declaration
public static bool operator ==(ContentReference x, ContentReference y)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | x | The x. |
ContentReference | y | The y. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if x.ID == y.ID and x.WorkID == y.WorkID and x.ProviderName == y.ProviderName otherwise false |
Inequality(ContentReference, ContentReference)
Implements the operator !=.
Declaration
public static bool operator !=(ContentReference x, ContentReference y)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | x | The x. |
ContentReference | y | The y. |
Returns
Type | Description |
---|---|
System.Boolean | The result of the operator. |
Explicit Interface Implementations
IReadOnly.CreateWritableClone()
Declaration
object IReadOnly.CreateWritableClone()
Returns
Type | Description |
---|---|
System.Object |