Reputation: 29301
I have an enum value in our server's solution:
public enum TaskStatus
{
//Description attribute modifies how an Enum's label is displayed when displayed via MVC.
[Description("Draft")]
Draft = 1,
[Description("Being Planned")]
BeingPlanned = 2,
[Description("Waiting For Change")]
WaitingForChange = 3,
[Description("In Progress")]
InProgress = 4,
[Description("Waiting For Customer Information")]
WaitingCustomerInformation = 5,
[Description("Cancelled")]
Cancelled = 6,
[Description("Completed")]
Completed = 7
};
This enum value gets serialized and passed over to a client as a WCF service reference.
I then display the Enum value in a model. Yet, I note that the Description attribute has been stripped from during the serialization/deserialization process.
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.450")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.cormant.com/cswebapi")]
public enum TaskStatus {
/// <remarks/>
Draft,
/// <remarks/>
BeingPlanned,
/// <remarks/>
WaitingForChange,
/// <remarks/>
InProgress,
/// <remarks/>
WaitingCustomerInformation,
/// <remarks/>
Cancelled,
/// <remarks/>
Completed,
}
I would still like to have the ability to describe how my enum's should be displayed to the end user. Is it possible to do this? Can I re-apply attributes after deserialization?
Upvotes: 2
Views: 89
Reputation: 16708
As far as my knowledge is concerned, you cannot transfer you attributes to client through code generation process by inclusion of WCF service reference. There is no way to get the attributes at client end.
While working for one project, i did one trick that was quite effective. I added that Enum file in Client project as a reference file (Add as a Link) as shown below:
This way you can have your copy of Enum with Description attribute at client-end. If you try to change it, you are actually changing the Server Enum file since it a reference file but the magic is that i will get compiled as part of your client project at the time of build process. Which is really a great workaround.
Hope this will help you :)
Upvotes: 1