我有一類具有枚舉EnumParentAttribute和智能感知
namespace Entities
{
public partial class OrderStatusType : Entity
{
public enum EOrderStatusType
{
P2 = 1,
Mounting = 2,
}
}
}
然後我有一個接口
namespace Interfaces
{
public interface IAttribute<T>
{
T Value { get; }
}
}
和另一類
namespace Entities
{
public partial class OrderStatus : Entity
{
[DataContract]
public enum EOrderStatus
{
[EnumMember(Value = "Film Ordered"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
FilmOrdered = 1,
[EnumMember(Value = "Not Started"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
NotStarted = 2,
[EnumMember(Value = "Cliche Ordered"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
ClicheOrdered = 3,
[EnumMember(Value = "Cliche In Stock"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
ClicheInStock = 4,
[EnumMember(Value = "Cliche Prepared"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
ClichePrepared = 5,
[EnumMember(Value = "Ready to start"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
Readytostart = 6,
[EnumMember(Value = "Started"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
Started = 7,
[EnumMember(Value = "Interrupted"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
Interrupted = 8,
[EnumMember(Value = "Completed"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
Completed = 9,
[EnumMember(Value = "ClichV status"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
ClichVstatus = 10,
[EnumMember(Value = "Cliche Mounting"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
ClicheMounting = 11,
[EnumMember(Value = "In Stock"), EnumParent(OrderStatusType.EOrderStatusType.P2)]
InStock = 12,
[EnumMember(Value = "Ordine con cilindri montati"), EnumParent(OrderStatusType.EOrderStatusType.Mounting)]
OrdineConCilindriMontati = 13,
}
[AttributeUsage(AttributeTargets.Field)]
public sealed class EnumParentAttribute : Attribute, Library.Interfaces.IAttribute<OrderStatusType.EOrderStatusType>
{
public EnumParentAttribute(OrderStatusType.EOrderStatusType EOrderStatusType) { this.mValue = EOrderStatusType; }
private OrderStatusType.EOrderStatusType mValue;
public OrderStatusType.EOrderStatusType Value { get { return mValue; } }
}
}
}
在類OrderStatus創建一個密封的子類從屬性繼承的EnumParentAttribute,實現了接口和我可以傳遞參數的地方OrderStatusType.EOrderStatusType類型,所以現在我可以使用自定義屬性EnumParent來裝飾枚舉EOrderStatus的項目,該自定義屬性接受OrderStatusType.EOrderStatusType類型的參數。
原因是我想在兩個枚舉之間創建一種父子關係。 但我想採取另一個步驟或兩個...
問:
1)如何添加,迫使我去裝點一新EOrderStatusType項目與自定義屬性「constarint」 EnumParent?有一種方法可以讓編譯器在編譯期間通知異常嗎? 2)如何擴展EOrderStatusType枚舉,以便我可以編寫如下代碼: OrderStatus.EOrderStatusType(P2)l_MyEnum = OrderStatus.EOrderStatus.FilmOrdered; Intellisense只顯示「正確」父項的項目嗎?
對不起,我的英語,我希望它是完全可以理解的......
提前感謝!