zoukankan      html  css  js  c++  java
  • 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

    EnumIntPropertyEditor_Win

    ASP.NET

    EnumIntPropertyEditor_Web

  • 相关阅读:
    转载——rdis安装yum版本
    Lc28_strStr kmp字符串匹配
    关于 哈希的总结
    Lc344_反转字符串
    Lc383_赎金信
    Lc454_四数相加 II
    Lc1_俩数之和
    推荐4款个人珍藏的IDEA插件!帮你写出不那么差的代码
    ZUC-生成随机序列
    移位运算
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Display-an-Integer-Property-as-an-Enumeration.html
Copyright © 2011-2022 走看看