wcftranslationenumsdatacontracts

Business enum to DatContract Enum conversion in WCF


I have an enum

namespace Business
{
    public enum Color
   {
       Red,Green,Blue
    }
}


namespace DataContract
{
   [DataContract] 
   public enum Color
   {
       [EnumMember]
       Red,
       [EnumMember]
       Green,
       [EnumMember]
       Blue
    }
}

I have the same enum as a datacontract in WCF with same values. I need to convert the Business enum to the DataContract enum using a translator.

Hoe can I achieve this?


Solution

  • If you know both types at the time you need to do the conversion you can do something like:

    Business.Color bc = Business.Color.Red;
    DataContract.Color dcc = (DataContract.Color)Enum.Parse(typeof(DataContract.Color), bc.ToString())