Interface IDynamicCode
Dynamic code 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.
[PublicApi_Stable_ForUseInYourCode]
public interface IDynamicCode : IHasLog
- Inherited Members
Properties
App
A fully prepared IApp object letting you access all the data and queries in the current app.
IApp App { get; }
Property Value
- IApp
The current app
CmsContext
This Context tells you about the environment, such as
- the current User
- the Page
- the View
- the Site
It's supposed to replace direct access to Dnn or Oqtane object in Razor and WebAPI code, allowing hybrid code that works everywhere.
ICmsContext CmsContext { get; }
Property Value
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.
dynamic Content { get; }
Property Value
- dynamic
A IDynamicEntity object with the current content - or null.
Data
The data prepared for the current Code. Usually user data which was manually added to the instance, but can also be a query.
IContextData Data { get; }
Property Value
- 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
IEditService Edit { get; }
Property Value
- 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.
dynamic Header { get; }
Property Value
- dynamic
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
ILinkService Link { get; }
Property Value
- ILinkService
A ILinkService object.
Methods
AsAdam(ICanBeEntity, string)
Provides an Adam instance for this item and field
IFolder AsAdam(ICanBeEntity item, string fieldName)
Parameters
item
ICanBeEntityThe item - an IEntity, IDynamicEntity, ITypedItem etc. often Content or similar
fieldName
stringThe field name, like "Gallery" or "Pics"
Returns
- 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.
dynamic AsDynamic(object dynamicEntity)
Parameters
dynamicEntity
objectthe original object
Returns
- dynamic
a dynamic object for easier coding
AsDynamic(string, string)
Take a json and provide it as a dynamic object to the code
dynamic AsDynamic(string json, string fallback = null)
Parameters
json
stringthe original json string
fallback
stringAlternate 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
- dynamic
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
dynamic AsDynamic(IEntity entity)
Parameters
entity
IEntitythe original object
Returns
- dynamic
a dynamic object for easier coding
AsEntity(object)
Unwraps a dynamic entity or ITypedItem back into the underlying IEntity
IEntity AsEntity(object dynamicEntity)
Parameters
dynamicEntity
objectthe wrapped IEntity
Returns
- IEntity
A normal IEntity
AsList(object)
Converts a list of IEntity objects into a list of IDynamicEntity objects.
IEnumerable<dynamic> AsList(object list)
Parameters
list
objecttypically a List/IEnumerable of Entities or DynamicEntities.
Can also be a IDataSource in which case it uses the default stream.
Returns
- IEnumerable<dynamic>
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.
T CreateSource<T>(IDataSource inSource = null, ILookUpEngine configurationProvider = null) where T : IDataSource
Parameters
inSource
IDataSourceThe data source which will be the default In of the new data-source.
configurationProvider
ILookUpEngineAn alternate configuration provider for the DataSource
Returns
- T
A typed DataSource object
Type Parameters
T
A data-source type - must be inherited from IDataSource
CreateSource<T>(IDataStream)
Create a IDataSource which will process data from the given stream.
T CreateSource<T>(IDataStream source) where T : IDataSource
Parameters
source
IDataStreamThe stream which will be the default In of the new data-source.
Returns
- T
A typed DataSource object
Type Parameters
T
A data-source type - must be inherited from IDataSource
GetService<TService>()
Get a service from the Dependency Injection. The service can come from 2sxc, EAV or the underlying platform (Dnn, Oqtane).
TService GetService<TService>() where TService : class
Returns
- TService
An object of the type or interface requested, or null if not found in the DI.
Type Parameters
TService
Interface (preferred) or Class which is needed