generic Mapper to Enumerations

  • Thread starter Alhambra Eidos Development
  • Start date
A

Alhambra Eidos Development

Hi all,

I have this issue.

I have two enumerations like this:

namespace WcfServices.Contracts
{
[System.Runtime.Serialization.DataContract]
public enum TipoRol
{
[System.Runtime.Serialization.EnumMember]
NoEspecificado,

[System.Runtime.Serialization.EnumMember]
Tomador,

[System.Runtime.Serialization.EnumMember]
Propietario,
}

and other enumeration, with THE SAME VALUES, but in another namespace



namespace DomainModel
{
public enum TipoRol
{
NoEspecificado,

Tomador,

Propietario,
}

I want to create EnumMapper generic like this

T EnumMapper<T,K>(value)

I want use like this:

WcfServices.Contracts.TipoRol value1 =
EnumMapper<WcfServices.Contracts.TipoRol, DomainModel.TipoRol>(
DomainModel.TipoRol.Propietario);


DomainModel.TipoRol value2 = EnumMapper<DomainModel.TipoRol,
WcfServices.Contracts.TipoRol >(WcfServices.Contracts..Propietario);

any idea please ?? I will be very grateful

thanks in advance
 
F

Family Tree Mike

Alhambra said:
Hi all,

I have this issue.

I have two enumerations like this:

namespace WcfServices.Contracts
{
[System.Runtime.Serialization.DataContract]
public enum TipoRol
{
[System.Runtime.Serialization.EnumMember]
NoEspecificado,

[System.Runtime.Serialization.EnumMember]
Tomador,

[System.Runtime.Serialization.EnumMember]
Propietario,
}

and other enumeration, with THE SAME VALUES, but in another namespace



namespace DomainModel
{
public enum TipoRol
{
NoEspecificado,

Tomador,

Propietario,
}

I want to create EnumMapper generic like this

T EnumMapper<T,K>(value)

I want use like this:

WcfServices.Contracts.TipoRol value1 =
EnumMapper<WcfServices.Contracts.TipoRol, DomainModel.TipoRol>(
DomainModel.TipoRol.Propietario);


DomainModel.TipoRol value2 = EnumMapper<DomainModel.TipoRol,
WcfServices.Contracts.TipoRol >(WcfServices.Contracts..Propietario);

any idea please ?? I will be very grateful

thanks in advance

I don't think you can use generics for the enums. Why not simply do
cast from one to the other like the following:

DomainModel.TipoRol tr = DomainModel.TipoRol.NoEspecificado;
WcfServices.Contracts.TipoRol tr2 = (WcfServices.Contracts.TipoRol)tr;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top