Interface IDynamicCode12
Interface for Dynamic Code with enhancements after v12. It extends IDynamicCode
Dynamic Code is the API for files like Razor or WebApis.
Supports many properties like App, etc. to ensure that the dynamic code has everything you need.
Also provides many Conversions between IEntity and IDynamicEntity.
Important for dynamic code files like Razor or WebApi. Note that there are many overloads to ensure that AsDynamic and AsEntity "just work" even if you give them the original data.
Inherited Members
Namespace: ToSic.Sxc.Code
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi]
public interface IDynamicCode12 : IDynamicCode, ICreateInstance, ICompatibilityLevel, IHasLog, ICompatibleToCode12
Properties
| Improve this Doc View SourceApp
A fully prepared IApp object letting you access all the data and queries in the current app.
Declaration
IApp App { get; }
Property Value
Type | Description |
---|---|
IApp | The current app |
CmsContext
The CmsContext tells you about the environment, like what page and module we're running in. It's supposed to replace the Dnn object in Razor and WebAPI code.
Declaration
ICmsContext CmsContext { get; }
Property Value
Type | Description |
---|---|
ICmsContext |
Remarks
New in v11.11
Content
The content object of the current razor view - IF the current view has content. If the view is a list, it will return the first item. Will be null otherwise. To tell if it's the demo/default item, use IsDemoItem.
Declaration
dynamic Content { get; }
Property Value
Type | Description |
---|---|
System.Object | A IDynamicEntity object with the current content - or null. |
Convert
Conversion helper for common data conversions in Razor and WebAPIs
Declaration
IConvertService Convert { get; }
Property Value
Type | Description |
---|---|
IConvertService |
Remarks
Added in 2sxc 12.05
Data
The data prepared for the current Code. Usually user data which was manually added to the instance, but can also be a query.
Declaration
IContextData Data { get; }
Property Value
Type | Description |
---|---|
IContextData | An IContextData which is as IDataSource. |
Edit
Helper commands to enable in-page editing functionality Use it to check if edit is enabled, generate context-json infos and provide toolbar buttons
Declaration
IEditService Edit { get; }
Property Value
Type | Description |
---|---|
IEditService | An IEditService object. |
Header
The header object of the current razor view, if it's a list and has a header object. If it's a list and doesn't have a header (and no default), it will return null. To tell if it's the demo/default item, use IsDemoItem.
Declaration
dynamic Header { get; }
Property Value
Type | Description |
---|---|
System.Object | A IDynamicEntity object with the current content. |
Remarks
Introduced in 2sxc 10.10 - previously it was called ListContent, now deprecated.
Link
Link helper object to create the correct links
Declaration
ILinkService Link { get; }
Property Value
Type | Description |
---|---|
ILinkService | A ILinkService object. |
Resources
Resources for this Scenario. This is a dynamic object based on the IDynamicStack.
It will combine both the Resources of the View and the App. The View-Resources will have priority. In future it may also include some global Resources.
🪒 Use in Razor: @Resources.CtaButtonLabel
Declaration
dynamic Resources { get; }
Property Value
Type | Description |
---|---|
System.Object |
Remarks
New in 12.03
Settings
Settings for this Scenario. This is a dynamic object based on the IDynamicStack.
It will combine both the Settings of the View and the App. The View-Settings will have priority. In future it may also include some global Settings.
🪒 Use in Razor: @Settings.ItemsPerRow
Declaration
dynamic Settings { get; }
Property Value
Type | Description |
---|---|
System.Object |
Remarks
New in 12.03
Methods
| Improve this Doc View SourceAsAdam(IEntity, String)
Provides an Adam instance for this item and field
Declaration
IFolder AsAdam(IEntity entity, string fieldName)
Parameters
Type | Name | Description |
---|---|---|
IEntity | entity | The entity, often Content or similar |
System.String | fieldName | The field name, like "Gallery" or "Pics" |
Returns
Type | Description |
---|---|
IFolder | An Adam object for navigating the assets |
AsAdam(IDynamicEntity, String)
Provides an Adam instance for this item and field
Declaration
IFolder AsAdam(IDynamicEntity entity, string fieldName)
Parameters
Type | Name | Description |
---|---|---|
IDynamicEntity | entity | The entity, often Content or similar |
System.String | fieldName | The field name, like "Gallery" or "Pics" |
Returns
Type | Description |
---|---|
IFolder | An Adam object for navigating the assets |
AsDynamic(Object)
Convert a dynamic entity and return itself again. This is so coders don't have to worry if the original object was an IEntity or a IDynamicEntity in the first place.
Declaration
dynamic AsDynamic(object dynamicEntity)
Parameters
Type | Name | Description |
---|---|---|
System.Object | dynamicEntity | the original object |
Returns
Type | Description |
---|---|
System.Object | a dynamic object for easier coding |
AsDynamic(Object[])
Convert one or many Entities and Dynamic entities into an IDynamicStack
Declaration
dynamic AsDynamic(params object[] entities)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | entities | one or more source object |
Returns
Type | Description |
---|---|
System.Object | a dynamic object for easier coding |
Remarks
New in 12.05
AsDynamic(String, String)
Take a json and provide it as a dynamic object to the code
Declaration
dynamic AsDynamic(string json, string fallback = "{}")
Parameters
Type | Name | Description |
---|---|---|
System.String | json | the original json string |
System.String | fallback | Alternate string to use, if the original json can't parse. Can also be null or the word "error" if you would prefer an error to be thrown. |
Returns
Type | Description |
---|---|
System.Object | A dynamic object representing the original json. If it can't be parsed, it will parse the fallback, which by default is an empty empty dynamic object. If you provide null for the fallback, then you will get null back. |
Remarks
Added in 2sxc 10.22.00
AsDynamic(IEntity)
Wraps an entity into a IDynamicEntity
Declaration
dynamic AsDynamic(IEntity entity)
Parameters
Type | Name | Description |
---|---|---|
IEntity | entity | the original object |
Returns
Type | Description |
---|---|
System.Object | a dynamic object for easier coding |
AsEntity(Object)
Unwraps a dynamic entity back into the underlying IEntity
Declaration
IEntity AsEntity(object dynamicEntity)
Parameters
Type | Name | Description |
---|---|---|
System.Object | dynamicEntity | the wrapped IEntity |
Returns
Type | Description |
---|---|
IEntity | A normal IEntity |
AsList(Object)
Converts a list of IEntity objects into a list of IDynamicEntity objects.
Declaration
IEnumerable<dynamic> AsList(object list)
Parameters
Type | Name | Description |
---|---|---|
System.Object | list | typically a List/IEnumerable of Entities or DynamicEntities. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Object> | a list of IDynamicEntity objects |
Remarks
Added in 2sxc 10.21.00
CreateSource<T>(IDataSource, ILookUpEngine)
Create a IDataSource which will process data from the given stream.
Declaration
T CreateSource<T>(IDataSource inSource = null, ILookUpEngine configurationProvider = null)
where T : IDataSource
Parameters
Type | Name | Description |
---|---|---|
IDataSource | inSource | The data source which will be the default In of the new data-source. |
ILookUpEngine | configurationProvider | An alternate configuration provider for the DataSource |
Returns
Type | Description |
---|---|
T | A typed DataSource object |
Type Parameters
Name | Description |
---|---|
T | A data-source type - must be inherited from IDataSource |
CreateSource<T>(IDataStream)
Create a IDataSource which will process data from the given stream.
Declaration
T CreateSource<T>(IDataStream source)
where T : IDataSource
Parameters
Type | Name | Description |
---|---|---|
IDataStream | source | The stream which will be the default In of the new data-source. |
Returns
Type | Description |
---|---|
T | A typed DataSource object |
Type Parameters
Name | Description |
---|---|
T | A data-source type - must be inherited from IDataSource |
GetService<TService>()
Get a service from the EAV / 2sxc Dependency Injection.
Declaration
TService GetService<TService>()
Returns
Type | Description |
---|---|
TService | An object of the type or interface requested |
Type Parameters
Name | Description |
---|---|
TService | Interface (preferred) or Class which is needed |
Remarks
Added in 2sxc 11.11