expressappframework-devexpress-dot-expressapp-dot-iobjectspace-dot-createobject-1.md
Creates an object of the type designated by the specified generic type parameter.
Namespace : DevExpress.ExpressApp
Assembly : DevExpress.ExpressApp.v25.2.dll
NuGet Package : DevExpress.ExpressApp
ObjectType CreateObject<ObjectType>()
Function CreateObject(Of ObjectType) As ObjectType
| Name |
|---|
| ObjectType |
| Type | Description |
|---|---|
| ObjectType |
A created object of the specified type.
|
The following code snippet uses a Parametrized Action to create a new Department object and add it to the Departments collection of the current Contact object.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
// ...
public class AddDepartmentController : ObjectViewController<DetailView, Contact> {
public AddDepartmentController() {
ParametrizedAction addDepartmentAction = new ParametrizedAction(this, "AddDepartment", PredefinedCategory.Edit, typeof(string));
addDepartmentAction.Execute += AddDepartmentAction_Execute;
}
private void AddDepartmentAction_Execute(object sender, ParametrizedActionExecuteEventArgs e) {
Department department = ObjectSpace.CreateObject<Department>();
department.Title = e.ParameterCurrentValue as string;
Contact contact = (Contact)View.CurrentObject;
contact.Departments.Add(department);
}
}
If you implement the IObjectSpace interface in the BaseObjectSpace class’ descendant, you don’t have to override the CreateObject<ObjectType> method entirely. The BaseObjectSpace.CreateObject<ObjectType> method invokes a protected virtual BaseObjectSpace.CreateObjectCore method and then sets the returned object modified by calling the BaseObjectSpace.SetModified method for it. So, you should only override the CreateObjectCore method.
The created object will be saved to the database when calling the IObjectSpace.CommitChanges method.
The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateObject<ObjectType>() method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
Book bookOne = ObjectSpace.CreateObject<Book>();
bookOne.Title = "A Visitor For Bear";
e.Context = TemplateContext.PopupWindow;
var template = os.CreateObject<OrderTemplate>();
e.View = Application.CreateDetailView(os, template);
}
Contact p1 = ObjectSpace.CreateObject<Contact>();
p1.FirstName = "Contact1";
ISecurityUserLoginInfo ISecurityUserWithLoginInfo.CreateUserLoginInfo(string loginProviderName, string providerUserKey) {
ApplicationUserLoginInfo result = ((IObjectSpaceLink)this).ObjectSpace.CreateObject<ApplicationUserLoginInfo>();
result.LoginProviderName = loginProviderName;
xaf-custom-list-editor-blazor/CS/XPO/CustomEditor/CustomEditor.Module/DatabaseUpdate/Updater.cs#L25
if (image1 == null) {
image1 = ObjectSpace.CreateObject<PictureItem>();
image1.Text = "Green";
Implements ISecurityUserWithLoginInfo.CreateUserLoginInfo
Dim result As ApplicationUserLoginInfo = DirectCast(CType(Me, IObjectSpaceLink).ObjectSpace.CreateObject(Of ApplicationUserLoginInfo)(), ApplicationUserLoginInfo)
result.LoginProviderName = loginProviderName
If sampleUser Is Nothing Then
sampleUser = ObjectSpace.CreateObject(Of PermissionPolicyUser)()
sampleUser.UserName = "User"
If sampleUser Is Nothing Then
sampleUser = ObjectSpace.CreateObject(Of PermissionPolicyUser)()
sampleUser.UserName = "User"
If administratorRole Is Nothing Then
administratorRole = ObjectSpace.CreateObject(Of PermissionPolicyRole)()
administratorRole.Name = "Administrators"
xaf-how-to-display-a-collection-property-as-a-checked-list-box/VB/DXExample.Module/Updater.vb#L20
If master Is Nothing Then
master = ObjectSpace.CreateObject(Of Master)()
master.MasterName = "TestMaster"
See Also