In this lesson, you will learn how to set the default value for a particular property of a business class. For this purpose, the Priority property will be added to the DemoTask class created in the Set a Many-to-Many Relationship (XPO) lesson. To initialize it, the AfterConstruction method will be overridden in this class.

在本课中,您将学习如何为 Business 类的特定属性设置默认值。为此,优先级属性将添加到在"设置多对多关系 (XPO)"一课中创建的 DemoTask 类中。要初始化它,将重写此类中的"构建后"方法。

Note

Before proceeding, take a moment to review the following lessons:

注意

在继续之前,请花点时间复习以下课程:

  • Inherit from the Business Class Library Class (XPO)
  • Set a Many-to-Many Relationship (XPO)
  • Add the Priority property to the DemoTask class and declare the Priority enumeration, as shown below:

  • 从 Business Class  继承(XPO)

  • 设置多对多关系 (XPO)

将"优先级"属性添加到 DemoTask 类并声明优先级枚举,如下所示:

public class DemoTask : Task {
// ...
private Priority priority;
public Priority Priority {
get { return priority; }
set {
SetPropertyValue(nameof(Priority), ref priority, value);
}
}
//...
}
public enum Priority {
Low = ,
Normal = ,
High =
}
  • To initialize the newly added Priority property when a DemoTask object is created, override the AfterConstruction method, as shown below:

  • 要在创建 DemoTask 对象时初始化新添加的"优先"属性,请重写 After 构造方法,如下所示:

    [DefaultClassOptions]
    [Custom("Caption", "Task")]
    public class DemoTask : Task {
    //...
    public override void AfterConstruction() {
    base.AfterConstruction();
    Priority = Priority.Normal;
    }
    //...
    }

    This method will be executed when the new DemoTask object is created. As a result, the Priority property will be initialized with the specified value. For details on the AfterConstruction method, refer to the PersistentBase.AfterConstruction Method topic in the XPO documentation.

创建新的 DemoTask 对象时,将执行此方法。因此,将用指定的值初始化"Priority"属性。有关后构造方法的详细信息,请参阅 XPO 文档中的持久基础.构建后方法主题。

  • Run the WinForms or ASP.NET application. Create a new DemoTask object by selecting DemoTask in the drop-down list of the New () button. (In the Detail View that represents the newly created DemoTask object, note that the Priority property is set to Normal, as declared in the code above.) Notice that the enumeration property is automatically displayed by the combo box editor.

  • 运行 WinForms 或ASP.NET应用程序。通过在"新建(new_dropdown_btn)"按钮的下拉列表中选择"演示任务",创建新的"演示任务"对象。(在表示新创建的 DemoTask 对象的详细信息视图中,请注意,优先级属性设置为"正常",如上述代码中声明的那样。请注意,枚举属性由组合框编辑器自动显示。

You can see the code demonstrated in this lesson in the MySolution.Module | Business Objects | DemoTask.cs (DemoTask.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/您可以在 MySolution.

模块中看到本课中演示的代码。业务对象 |DemoTask.cs (DemoTask.vb) 文件的主演示安装与 XAF.默认情况下,主演示应用程序安装在 %PUBLIC%_文档_DevExpress 演示 19.2_组件_eXpressApp 框架_MainDemo 中。ASP.NET版本可在 http://demos.devexpress.com/XAF/MainDemo/ 在线获取

Initialize a Property After Creating an Object 创建对象后初始化属性 (XPO)的更多相关文章

  1. Initialize a Property After Creating an Object创建对象后初始化属性 即如何设置对象的默认值(EF)

    In this lesson, you will learn how to set the default value for a particular property of a business ...

  2. Creating default object from empty value in PHP?

      Your new environment may have E_STRICT warnings enabled in error_reporting if it is PHP <= 5.3, ...

  3. 在使用Ibatis查询数据返回时,报如下错误:java ibatis The error happened while setting a property on the result object

    问题: 在使用Ibatis查询数据返回时,报如下错误: [com.show.add.proxy.SqlMapClientTemplateProxy]com.ibatis.common.jdbc.exc ...

  4. log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [File] to set object on [TF.Log.FileAppender]

    难受,香菇. 大概研究了两个多小时,搜了很多资料都没有很完美的答案,最后突然脑子就一闪一闪,才弄明白咋回事. log4net:ERROR XmlHierarchyConfigurator: Canno ...

  5. hp警告Creating default object from empty value 问题的解决方法

    hp警告Creating default object from empty value 问题的解决方法 解决方法是找到报错的位置然后看哪个变量是没有初始化而直接使用的,将这个变量先实例化一个空类.如 ...

  6. Adding property to a json object in C#

    Adding property to a json object in C#   you can do it with a dynamic object dynamic obj = JsonConve ...

  7. Wordpress里提示警告信息creating default object from empty value in *** 的解决方法

    PHP里提示 Creating default object from empty value 的问题,一般是由于PHP版升级的原因,PHP 5.4 以上的版本一般会报这个错误.PHP的解决方法:找到 ...

  8. JS面向对象(3) -- Object类,静态属性,闭包,私有属性, call和apply的使用,继承的三种实现方法

    相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...

  9. QML Object Attributes QML对象属性

    QML Object Attributes Every QML object type has a defined set of attributes. Each instance of an obj ...

随机推荐

  1. 远程桌面MATLAB启动失败问题解决

    博客:博客园 | CSDN | blog 远程桌面打开MATLAB会报错,解决办法,打开matlab的licenses路径,如matlab/R2017b/licenses/,路径下存有license文 ...

  2. PyTorch-网络的创建,预训练模型的加载

    本文是PyTorch使用过程中的的一些总结,有以下内容: 构建网络模型的方法 网络层的遍历 各层参数的遍历 模型的保存与加载 从预训练模型为网络参数赋值 主要涉及到以下函数的使用 add_module ...

  3. 高性能mysql——高性能索引策略

    <高性能MySQL>读书笔记 一. 索引的优点 1. 索引可以让服务器快速定位到表的指定位置,大大减少了服务器需要扫描的数量: 2. 最常见的B-Tree索引按照顺序存储数据,可以用来做o ...

  4. C#_.NetCore_WebAPI项目_EXCEL数据导出(ExcelHelper_第二版_优化逻辑)

    项目需要引用NPOI的Nuget包:DotNetCore.NPOI-v1.2.2 本篇文章是对WebAPI项目使用NPOI操作Excel时的帮助类:ExcelHelper的改进优化做下记录: 备注:下 ...

  5. ERP系统到底能做什么?

    ERP的定义:在先进的企业管理思想的基础上,应用信息技术实现对整个企业资源的一体化管理. 关键词:信息技术 先进的管理思想 企业资源一体化: 那么,ERP系统在企业日常经营管理中到底能做什么? 1.在 ...

  6. 解决Android调用相机拍照,要报“打开相机失败”查看debug日志显示“setParameters failed”的问题

    使用CameraLibrary项目,在部分手机或平板上不能正常使用,要报“打开相机失败”查看debug日志显示“setParameters failed”. 找到CameraView.java中的se ...

  7. 不看好 git ,也看不懂为什么那么多人去使用 git

    上来就亮明观点,符合我的性格.呵呵呵. 为什么不看好 git 呢? 首先,我们来看看 git 产生的背景. git 是 Linus 开发的,最初的目的,是为了管理 Linux 系统的源代码.这是一个分 ...

  8. 浅析ketamahash和murmurhash

    说来赶巧,之前我有16个redis集群,然后我要将某个key根据路由规则存到16个集群中的某一个上面,正巧用到了这两种哈希算法,改造完毕上线后,整体带来的效果也十分理想. 说道ketamahash,它 ...

  9. Vue 04

    目录 创建Vue项目 Vue项目环境搭建 Vue项目创建 pycharm配置并启动vue项目 vue项目目录结构分析 项目生命周期 添加组件-路由映射关系 文件式组件结构 配置全局css样式 子组件的 ...

  10. 使用 mitmdump 进行 selenium webDriver绕过网站反爬服务的方法 pdd某宝 可用

    安装:  pip install  mitmproxy 新建一个脚本 脚本代码: from mitmproxy import ctx injected_javascript = ''' // over ...