Class CustomModel
Base class for custom models. Similar to CustomItem but without predefined public properties or methods.
[PublicApi]
public class CustomModel : ModelFromItem, ICanWrap<ITypedItem>, ICanWrapData, IEquatable<ITypedItem>
- Inheritance
-
objectCustomModel
- Implements
- Inherited Members
Examples
Usage ca. like this:
- A custom data model in
AppCode.Data
which inherits from this class (usually generated by 2sxc Copilot) - Razor code which uses it to convert typed items into this custom data model
Example trivial custom data model:
namespace AppCode.Data
{
class MyPersonModel : Custom.Data.CustomModel
{
// New custom property
public string Name => _item.String("Name");
}
}
Example usage in Razor:
@inherits Custom.Hybrid.RazorTyped
@using AppCode.Data
@{
var person = As<MyPersonModel>(MyItem);
}
@* Now you can use the custom properties *@
<span>@person.Name</span>
@* But NOT all the standard properties like Id, Guid, Title, Type, etc. *@
@* this would error: *@
<span>@person.Id / @person.Guid</span>
Remarks
This is a lightweight custom object which doesn't have public properties
like Id
or methods such as String(...)
.
It's ideal for data models which need full control, like for serializing or just to reduce the API surface.
You can access the underlying (protected) _item
property to get the raw data.
And it also has the (protected) As<...>()
conversion for typed sub-properties.
History: New in 19.03