Explicitly typed content
When the model is known in advance, you may prefer to work with explicitly typed content.
The following example demonstrates this case for news items, but you can also use it for any kind of dynamic content.
Dynamic content is referenced with the full type name
Telerik.Sitefinity.DynamicTypes.Model.{ModuleName}.{TypeName}, for example
Telerik.Sitefinity.DynamicTypes.Model.Pressreleases.Child
In the following example, the NewsDto
represents the News content:
There are the following things to note in the above example:
- The
NewsDto
inherits from SdkItem
.
This gives you the method GetValue
, and the properties Id
and Provider
.
- The class is marked with the attribute
MappedSitefinityTypeAttribute
.
This holds the CRL type of the mapped Sitefinity type. In this case,
RestClientContentTypes.News = "Telerik.Sitefinity.News.Model.NewsItem"
- All of the custom properties are defined.
RECOMMENDATION: The REST SDK provides DTOs for all static types, such as news, events, lists, taxons, taxonomies, media, pages, and page templates. Therefore, you do not need to define them yourself, unless you want to define your custom fields in a custom DTO class. In this case, we recommend inheriting from the already defined types and adding your custom fields there.