Skip to content
Loading
list object if contain one value then return another one c#
  • Nitin Sontakke
    @Fabio,
     
    Agreed in principle. However, just for record, specific to xml serialization, enum values can be decorated with an attribute as follows:
     
    [XmlEnum(Name="High")]
  • Fabio Silva Lima
    @Nitin I agree but it depends what he is trying to do. He can face a serialization problem with enum. If the frontend expects an integer when we use enum it's serialize as string and other problems with database.
     
    @Ujjwal I do not like to use switch because a new priority you will need to add one more case. But i liked you separate method for the conversion.
  • Nitin Sontakke
    Even better approach would be to have a property of enum's type as:
     
    public PriorityType Priority {get; set;} 
  • Fabio Silva Lima
    create a enum and convert Priority.
     
    1. public class DocumentsUser    
    2.     {    
    3.   public string Priority { getset; }    
    4. }    
    5.   
    6. public enum PriorityType{  
    7.  High = 3,  
    8.   Medium = 2,  
    9.   Low = 1  
    10. }  
    11.     
    12. var objUserSetUp = objUserSetUp1.Select(m => new {Priority = (PriorityType)m.Priority});