有如下业务对象定义:
using System; using System.Linq; using System.Text; using DevExpress.Xpo; using DevExpress.ExpressApp; using System.ComponentModel; using DevExpress.ExpressApp.DC; using DevExpress.Data.Filtering; using DevExpress.Persistent.Base; using System.Collections.Generic; using DevExpress.ExpressApp.Model; using DevExpress.Persistent.BaseImpl; using DevExpress.Persistent.Validation; namespace TestXPO.Module.BusinessObjects { //往来单位:供应商,客户都是此类的派生类 [XafDefaultProperty("Name")] [DefaultClassOptions] public abstract class CompanyUnit : BaseObject { public CompanyUnit(Session s) : base(s) { } public string Name { get { return GetPropertyValue<string>(nameof(Name)); } set { SetPropertyValue(nameof(Name), value); } } } [DefaultClassOptions] [XafDefaultProperty(nameof(Address))] public class Customer : CompanyUnit { public Customer(Session s) : base(s) { } public string Address { get { return GetPropertyValue<string>(nameof(Address)); } set { SetPropertyValue(nameof(Address), value); } } } [DefaultClassOptions] public class Provider : CompanyUnit { public Provider(Session s) : base(s) { } } public class Dept : CompanyUnit { public Dept(Session s) : base(s) { } } //存在某种单据基类: //使用了CompanyUnit做为属性的类型 //在派生类中new TargetUnit重新定义此属性的类型,则可以成功 //可以达到使用真实类型过滤的作用. //但如果使用Guid类型声明,并且派生类中用复杂类型,则不能成功 [DefaultClassOptions] public class FormBase : BaseObject { public FormBase(Session session) : base(session) { } public CompanyUnit TargetUnit { get { return GetPropertyValue<CompanyUnit>(nameof(TargetUnit)); } set { SetPropertyValue(nameof(TargetUnit), value); } } } [DefaultClassOptions] public class PMSOrder : FormBase { public PMSOrder(Session s) : base(s) { } public new Provider TargetUnit { get { return GetPropertyValue<Provider>(nameof(TargetUnit)); } set { SetPropertyValue(nameof(TargetUnit), value); } } } [DefaultClassOptions] public class SMSOrder : FormBase { public SMSOrder(Session s) : base(s) { } public new Customer TargetUnit { get { return GetPropertyValue<Customer>(nameof(TargetUnit)); } set { SetPropertyValue(nameof(TargetUnit), value); } } } }
时间: 2024-10-09 05:39:51