Content Metadata properties
Describes metadata interfaces and metadata properties that you can define on content models.
EPiServer.Core.IContentData is the base interface that all content models implement. All content types, except BlockData, also implement EPiServer.Core.IContent. This interface gives a content instance a unique ID and its own lifecycle: it can be loaded or saved individually. The EPiServer.IContentRepository performs CRUD (Create, Read, Update, Delete) operations on content instances implementing EPiServer.Core.IContent.
Content types also implement additional metadata interfaces that define their characteristics. The following list describes each metadata interface and its properties.
Usage
Some interfaces are optional. Use the is or as operators to check whether an IContent instance implements an interface, as in this example:
public static CultureInfo Language(this IContent content) {
if (content == null) throw new ArgumentNullException(nameof(content));
return (content is ILocale locale) ? locale.Language : CultureInfo.InvariantCulture;
}
public static bool IsModified(this IContent content) {
if (content == null) throw new ArgumentNullException(nameof(content));
var modifiedTrackable = content as IModifiedTrackable;
return modifiedTrackable == null || modifiedTrackable.IsModified;
}Shared blocks
Understand how shared block instances gain IContent identity at runtime. BlockData does not implement IContent, but shared block instances have their own identity defined on IContent. At runtime, when a shared block instance is created (for example, through IContentRepository.GetDefault<T> where T inherits from BlockData), Optimizely CMS creates a .NET type inheriting T using a technique called mixin. The generated subclass implements extra interfaces, including IContent.
A shared block instance of T implements IContent, while an instance of T used as a property on a page does not.
IContentData
This base interface for content models contains a backing PropertyDataCollection used when loading or saving data from the database.
Property(PropertyDataCollection) – Contains backing data for properties used by the content instance.
IContent
This base interface gives content models their own identity, enabling individual loading and saving. IContent inherits IContentData. ContentLink.ID and ContentGuid are the same for all language branches of a content item. The combination of ContentLink or ContentGuid and ILocale.Language uniquely identifies the content instance (if it implements ILocalizable). All built-in base content types, except BlockData, implement IContent. Shared block instances implement IContent (and most other metadata interfaces) at runtime.
Name(string) – The name of the content instance.ContentLink(ContentReference) – The identifier of the content instance. WorkID specifies an optional version ID, in case the instance represents a specific version.ContentGuid(Guid) – A GUID-based identifier for the content instance.ParentLink(ContentReference) – The parent identifier (in a tree structure) for the content instance.ContentTypeID(int) – An identifier that specifies which content type the content is an instance of.IsDeleted(bool) – Indicates if the content instance is in the wastebasket.Property(PropertyDataCollection) – Inherited fromIContentData.
IVersionable
This optional interface supports different versions for each language branch. Only one version can be published at a time. Built-in types, except ContentFolder, implement IVersionable. See Content versions.
Status(VersionStatus) – Specifies the status of the content version.IsPendingPublish(bool) – Specifies if there is any published version for the current language branch.StartPublish(DateTime?) – Optional value that specifies when the content is/was published.StopPublish(DateTime?) – Optional value that specifies when the content is/was depublished.
ILocale
This optional interface specifies the language of a content instance. All built-in types except ContentFolder implement ILocale.
Language(CultureInfo) – Specifies the language of a content instance.CultureInfo.InvariantCulturemeans that the content instance is not culture-specific.
ILocalizable
This optional interface supports multiple language branches. It inherits ILocale. All built-in types, except ContentFolder and MediaData, implement ILocalizable.
Language(CultureInfo) – Inherits fromILocale.MasterLanguage(CultureInfo) – Specifies which language version contains the non-language-specific properties.ExistingLanguages(IEnumerable<CultureInfo>) – Specifies all existing language branches for this content.
IReadOnly/IReadOnly<T>
Implement IReadOnly on content types to ensure integrity when the cache serves and reuses instances across requests. All built-in base content classes implement IReadOnly.
IsReadOnly(bool) – Specifies if the current instance is read-only.void MakeReadOnly()(Method) – Makes an instance read-only.object/T CreateWritableClone()(Method) – Creates a writable clone from a read-only instance.
IModifiedTrackable
IModifiedTrackable improves save performance by persisting only changed data. Built-in base content classes implement IModifiedTrackable.
IsModified(bool) – Specifies if the current instance is modified.void ResetModified()(Method) – Sets the content instance in a non-modified state.
IChangeTrackable
This optional interface tracks changes on content instances. All built-in base content classes implement IChangeTrackable.
Created(DateTime) – The date and time when the content instance was created.CreatedBy(string) – The username of the user that created the content instance.Changed(DateTime) – The date when the content instance was last marked as changed.SetChangedOnPublish(bool) – Whether the Changed date should be updated on publish.ChangedBy(string) – The username of the user that most recently changed the content instance.Saved(DateTime) – The date and time when the content instance was last saved.DeletedBy(string) – The username of the user who deleted the content.Deleted(DateTime?) – The deleted date.
IContentSecurable
This optional interface supports access checks on content instances. All built-in base content classes implement IContentSecurable.
IContentSecurityDescriptorandGetContentSecurityDescriptor()(Method) – Gets the security descriptor for the content instance where access rights can be checked.
IRoutable
Content items that need routing through a content URL implement this interface. All built-in base content classes, except shared blocks, implement IRoutable.
RouteSegment(string) – Specifies the route segment used in the hierarchical content URL for the content instance.
ICategorizable
Content items that support categorization implement this interface. Built-in base content classes, except content folders, implement ICategorizable.
Category(CategoryList) – A list of all categories that this content instance is categorized as.
IInitializableContent
This optional interface sets default values when creating an instance of a content type.
void SetDefaultValues(ContentType contentType)(Method) – Called when an instance of the content type is created.
IExportable
This optional interface specifies how to handle a content instance during export.
ShouldBeImplicitlyExported(bool) – Specifies whether this instance should be implicitly added to the export package when referenced by some exported entity.
Updated 18 days ago
