简体   繁体   English

向温莎城堡注册枚举

[英]Register Enumeration with Castle Windsor

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. 两个枚举都位于不同的命名空间中。

I don't think you can switch enum values using Castle.Windsor, but you could try the following 我认为您无法使用Castle.Windsor切换枚举值,但是您可以尝试以下操作

// 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 您还将被迫解决您感兴趣的特定类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM