Question

I am not sure if this is possible but i have a enum like so

public enum StopCode
{
   StartProd = 77,
   BeaOmstilling = 45,
   FlexOmstilling = 47,
   PlaStop = 32,
}

and the enum has different values in some cases depending on which country the program runs for.

public enum StopCode
{
    StartProd = 20,
    BeaOmstilling = 25,
    FlexOmstilling = 97,
    PlaStop = 62,
}

Are there any way that i can register both enum values in Castle Windsor. Both Enum's are in different namespaces.

Was it helpful?

Solution

I don't think you can switch enum values using Castle.Windsor, but you could try the following

// declare the enum
public enum StopCode
{
    StartProd,
    BeaOmstilling,
    FlexOmstilling,
    PlaStop,
}

// and declare an interface that translates this enum to values
public interface StopCodeConverter
{
    int convertFrom(StopCode code);
}

// then your components
public class EnglishStopCodeConverter
{
    public int convertFrom(StopCode code) { /* do your translation */ return  0;}
}

public class SpanishStopCodeConverter
{
    public int convertFrom(StopCode code) { /* hace su translaciòn */ return  0;}
}

Resolve the correct implementation when needed and you have your localized enum values.


EDIT: even with the enums in different namespaces i don't think it is a good idea to change the values in the enum, since the different types will cause your code to be split along these types. You would also be forced to resolve the specific type you're interested into

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top