Interface IDynamicEntity
This is an older dynamic wrapper for IEntity objects. It provides dynamic access to underlying properties.
[PublicApi]
public interface IDynamicEntity : IHasDecorators<IEntity>, IMultiWrapper<IEntity>, ICanDebug
- Inherited Members
Remarks
It provides nicer access to underlying properties and automatically handles things like multi-language etc. The underlying IEntity IEntity is in the Entity property.
This is an older way to work with entities and not recommended anymore. You should use a newer base class such as `RazorTyped`, there Dynamic objects are not used anymore.
Normally you will use it without caring about these internals.
Please check @HowTo.DynamicCode.DynamicEntity
Properties
AnyProperty
A Dynamic Entity always contains an item of your data - a book, person, blog-post or a piece of content.
Since the object is dynamic, you can just use .IsFemale or whatever other property your item has.
It is treated as a dynamic so you can just output it, or cast it to the expected type.
dynamic? AnyProperty { get; }
Property Value
- dynamic
EntityGuid
The guid of the underlying entity.
Guid EntityGuid { get; }
Property Value
Remarks
If the entity doesn't exist, it will return an empty guid
EntityId
The ID of the underlying entity. Use it for edit-functionality or just to have a unique number for this item.
int EntityId { get; }
Property Value
Remarks
If the entity doesn't exist, it will return 0
EntityTitle
The title of this item. This is always available no matter what the underlying field for the title is.
string? EntityTitle { get; }
Property Value
- string
The title of the underlying entity. In rare cases where no title-field is known, it can be null. It can also be null if there is no underlying entity.
Remarks
This returns a string which is usually what's expected. In previous versions (before v15) 2sxc it returned an object.
EntityType
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
string? EntityType { get; }
Property Value
IsDemoItem
Many templates show demo data.
If the template code must know if it's the demo item or
real data, use .IsDemoItem.
bool IsDemoItem { get; }
Property Value
- bool
True if this is the item configured in the view-settings, false if not.
Remarks
New in 10.07 on IDynamicEntity, new in 16.02 on ITypedEntity
IsPublished
Tells us if this data item is published or still draft. Default is true.
bool IsPublished { get; }
Property Value
Metadata
The type name of the current entity. This provides the nice name like "Person" and not the technical internal StaticName
dynamic Metadata { get; }
Property Value
- dynamic
Remarks
- Added in v13
- Changed type name to
IMetadatafromIDynamicMetadatain 16.02; same type, different type name - Changed type to
dynamicin v20 since we believe all use cases in the wild always use dynamic access.
Presentation
Contains presentation settings for an item - if they exist.
This is a functionality of the CMS, where an instance of an item can be configured to show in a specific way.
Normally it's used when something like an address has various show-settings (like how the map should visualize this address).
The presentation-info is therefor not-null IF
- the content belongs to this module instance
- the view-configuration of this module is configured to have presentation items
- there is either a default presentation configured in the view, or the user has manually edited the presentation settings
dynamic? Presentation { get; }
Property Value
- dynamic
An IDynamicEntity with the presentation item (or the demo-presentation), otherwise null.
Methods
Children(string?, string?)
A dynamic list of sub-items. Important for LINQ style querying or just
working with various lists. Note that for getting child items of this item you
can just use the properties, like content.Authors.
But using Children("Authors", typeName) gives you the ability to restrict to a type.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
List<IDynamicEntity?> Children(string? field = null, string? type = null)
Parameters
fieldstringOptional field filter - would only return items that point to the current item in a specific field name.
typestringOptional type filter - would only return items of this type.
Returns
- List<IDynamicEntity>
A list of all items pointing here (filtered), converted to DynamicEntity for convenience.
Remarks
New in 10.21.00 - note also that the parameter-order is reversed to the Parents()
Field(string)
Get a Field-object of a property of this entity, to use with services like the IImageService which also need more information like the metadata.
IField? Field(string name)
Parameters
namestring
Returns
Remarks
History: Added in v13.10
Get(string)
Get a value of the entity. Usually you will prefer the quick access like @content.FirstName - which will give you the same things as content.Get("FirstName"). There are two cases to use this:
- when you dynamically assemble the field name in your code, like when using App.Resources or similar use cases.
- to access a field which has a conflicting name with this object, like Get("Parents")
dynamic? Get(string name)
Parameters
namestring
Returns
- dynamic
An object which can be either a string, number, boolean or List<IDynamicEntity>, depending on the field type. Will return null if the field was not found.
Get(string, NoParamOrder, string?, bool, bool?)
Get a property using the string name. Only needed in special situations, as most cases can use the object.name directly
dynamic? Get(string name, NoParamOrder noParamOrder = default, string? language = null, bool convertLinks = true, bool? debug = null)
Parameters
namestringthe property name like
Image- or path likeAuthor.Name(new v15)noParamOrderNoParamOrderlanguagestringOptional language code - like "de-ch" to prioritize that language
convertLinksboolOptionally turn off if links like file:72 are looked up to a real link. Default is true.
debugbool?Set true to see more details in Insights how the value was retrieved.
Returns
- dynamic
a dynamically typed result, can be string, bool, etc.
GetDraft()
Get the draft item of this item if this is a content-item which is published, and has a draft.
dynamic? GetDraft()
Returns
- dynamic
Returns a dynamic entity if there is a draft, or null if there is no draft.
GetPublished()
Get the published item of this item if this is a content-item which is draft, and has a published.
dynamic? GetPublished()
Returns
- dynamic
Returns a dynamic entity if there is a draft, or null if there is no draft.
Get<TValue>(string)
Get a value using the name - and cast it to the expected strong type. For example to get an int even though it's stored as decimal.
TValue? Get<TValue>(string name)
Parameters
namestringthe property name like
Image- or path likeAuthor.Name(new v15)
Returns
- TValue
The typed value, or the
defaultlikenullor0if casting isn't possible.
Type Parameters
TValueThe expected type, like
string,int, etc.
Remarks
Added in v15
Get<TValue>(string, NoParamOrder, TValue?)
Get a value using the name - and cast it to the expected strong type. For example to get an int even though it's stored as decimal.
Since the parameter fallback determines the type TValue you can just write this like
`Content.Get("Title", fallback: "no title")
TValue? Get<TValue>(string name, NoParamOrder noParamOrder = default, TValue? fallback = default)
Parameters
namestringthe property name like
Image- or path likeAuthor.Name(new v15)noParamOrderNoParamOrderfallbackTValuethe fallback value to provide if not found
Returns
- TValue
The typed value, or the
defaultlikenullor0if casting isn't possible.
Type Parameters
TValueThe expected type, like
string,int, etc. Note that you don't need to specify it, if you specify thefallbackproperty.
Remarks
Added in v15
Html(string, NoParamOrder, object?, bool?, object?, bool)
Show a field in the expected / the best possible way. As of now it's meant for WYSIWYG fields with Very-Rich Text. See DynamicEntity / TypedItem .Html(...) Method new v16.01
IHtmlTag? Html(string name, NoParamOrder noParamOrder = default, object? container = null, bool? toolbar = null, object? imageSettings = null, bool debug = false)
Parameters
namestringthe field name
noParamOrderNoParamOrdercontainerobjectA wrapper tag for the result. It's either a RazorBlade tag such as
Kit.HtmlTag.Div(), a string such asspanor an empty string `` to indicate no container. If not set it will default to a div-tag. See docstoolbarbool?Override default toolbar behavior on this field. See docs
imageSettingsobjectSettings for resizing. Default is
Wysiwygbut it can also beContentor a settings object.debugboolActivate debug visualization to better see alignments and such.
Returns
Remarks
- Added in 2sxc 16.01
- Only works on Razor files inheriting from Hybrid14 or newer
Parents(string?, string?)
A dynamic list of entities which point to this item. Important for LINQ style querying or just
working with various lists. Note that for getting child items of this item you
can just use the properties, like content.Authors.
Please check the tutorials on 2sxc.org/dnn-tutorials/ for more info.
List<IDynamicEntity?> Parents(string? type = null, string? field = null)
Parameters
typestringOptional type filter - would only return items of this type.
fieldstringOptional field filter - would only return items that point to the current item in a specific field name.
Returns
- List<IDynamicEntity>
A list of all items pointing here (filtered), converted to DynamicEntity for convenience.
Remarks
New in 9.42 - note also that the parameter-order is reversed to the Children()