How to: Display an Integer Property as an Enumeration 如何:将整数属性显示为枚举
This topic describes how to display a business class integer property as an enumeration, in case you do not wish to modify (or cannot modify) the source code of this class.
本主题介绍如何将 Business 类整数属性显示为枚举,以防您不希望修改(或无法修改)此类的源代码。
Note 注意
Mobile applications do not support displaying of a business class integer property as an enumeration, so the approach described in this topic cannot be implemented in the Mobile platform. If it is necessary to implement this scenario in your Mobile application, contact us using the Support Center
移动应用程序不支持将 Business 类整数属性显示为枚举,因此本主题中描述的方法无法在移动平台中实现。如果需要在移动应用程序中实施此方案,请使用支持中心与我们联系
.
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4925
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E4925
Consider the following SampleObject business class.
请考虑以下示例对象业务类。
[DefaultClassOptions] public class SampleObject : BaseObject { public SampleObject(Session session) : base(session) { } private string name; public string Name { get { return name; } set { SetPropertyValue(nameof(Name), ref name, value); } } private int integerProperty; public int IntegerProperty { get { return integerProperty; } set { SetPropertyValue(nameof(IntegerProperty), ref integerProperty, value); } } }
Assume that this class is located in an external assembly, and you cannot modify its code. The task is to display enumeration values instead of integers (e.g., Value1 for zero, Value2 for 1, etc.). Follow the steps below to learn how to solve this task.
假设此类位于外部程序集中,并且无法修改其代码。任务是显示枚举值而不是整数(例如,零值 1,值 2 表示 1 等)。请按照以下步骤了解如何解决此任务。
1. Implement an enumeration whose values will be mapped to integer values.
实现其值将映射到整数值的枚举。
public enum SampleEnum { Value1, Value2, Value3}
2. In a WinForms module project, create a custom MyEnumIntPropertyEditor Property Editor by inheriting the EnumIntPropertyEditor<SampleEnum> class. Note that your editor should be public.
在 WinForms 模块项目中,通过继承枚举IntPropertyeditor<SampleEnum>类来创建自定义的 MyEnumIntPropertyEditor 属性编辑器。请注意,您的编辑器应该是公开的。
using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Win.Editors; // ... [PropertyEditor(typeof(int), false)] public class MyEnumIntPropertyEditor : EnumIntPropertyEditor<SampleEnum> { public MyEnumIntPropertyEditor(Type objectType, IModelMemberViewItem model) : base(objectType, model) { } }
3. Run the Model Editor for the WinForms module project. Set the IModelCommonMemberViewItem.PropertyEditorType property of the BOModel | OwnMembers | IntegerProperty node to MyEnumIntPropertyEditor.
运行 WinForms 模块项目的模型编辑器。设置 BOModel 的 IModel 通用成员视图项.属性编辑器类型属性 |自己的会员 |到 MyEnumIntProperty 编辑器的整数属性节点。
4. In an ASP.NET module project, create a custom MyEnumIntPropertyEditor Property Editor by inheriting the ASPxEnumIntPropertyEditor<SampleEnum> class. Note that your editor should be public.
在ASP.NET模块项目中,通过继承 ASPxnumIntPropertyEditor<SampleEnum> 类来创建自定义的 MyEnumIntPropertyEditor 属性编辑器。请注意,您的编辑器应该是公开的。
using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Web.Editors.ASPx; using DevExpress.ExpressApp.Model; // ... [PropertyEditor(typeof(int), false)] public class ASPxMyEnumIntPropertyEditor : ASPxEnumIntPropertyEditor<SampleEnum> { public ASPxMyEnumIntPropertyEditor(Type objectType, IModelMemberViewItem model) : base(objectType, model) { } }
5. Run the Model Editor for the ASP.NET module project. Set the IModelCommonMemberViewItem.PropertyEditorType property of the BOModel | OwnMembers | IntegerProperty node to ASPxMyEnumIntPropertyEditor.
运行ASP.NET模块项目的模型编辑器。设置 BOModel 的 IModel 通用成员视图项.属性编辑器类型属性 |自己的会员 |到 ASPxMyEnumInt 属性编辑器的整数属性节点。
The images below illustrate the results in a WinForms application and an ASP.NET application.
下图说明了 WinForms 应用程序和ASP.NET应用程序的结果。
WinForms
ASP.NET
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:
![](http://files.cnblogs.com/files/foreachlife/wx.bmp)