enum

Use enum in h:selectManyCheckbox

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to use enum values in a . The checkboxes get populated correctly, however, when selecting some values and submitting them, their runtime type is String , and not enum. My code: UserController class (SecurityRole is an enum type): public SelectItem[] getRolesSelectMany() { SelectItem[] items = new SelectItem[SecurityRole.values().length]; int i = 0; for (SecurityRole role : SecurityRole.values()) { items[i++] = new SelectItem(role, role.toString()); } return items; } public List getRoles() { getCurrent().getRoles(); } public void

enum-int casting: operator or function

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In the external code that I am using there is enum: enum En {VALUE_A, VALUE_B, VALUE_C}; In another external code that I am using there are 3 #define directives: #define ValA 5 #define ValB 6 #define ValC 7 Many times I have int X which is equal to ValA or ValB or ValC, and I have to cast it to the corresponding value of En (ValA to VALUE_A, ValB to VALUEB, etc) because some function signature has enum En. And many times I have to do the opposite operation, translate enum En to ValA or ValB or ValC. I cannot change the signatures of these

Get XmlEnumAttribute from enum

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have enum: public enum Operation { /// [System.Xml.Serialization.XmlEnumAttribute("01")] Item01, /// [System.Xml.Serialization.XmlEnumAttribute("02")] Item02, /// [System.Xml.Serialization.XmlEnumAttribute("03")] Item03, /// [System.Xml.Serialization.XmlEnumAttribute("04")] Item04, } How I can get XmlEnumAttribute value? I'm trying at that: var res = Operation.Item1; var result = (res.GetType().GetField("Item01").GetCustomAttributes(typeof(XmlEnumAttribute), true)[0] as XmlEnumAttribute).Name; May be exists better method? 回答1: You could

Passing an enum value as command parameter from XAML

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to pass an enum value as command parameter in WPF, using something like this: SearchPageType is an enum and this is to know from which button search command is invoked. Is this possible in WPF, or how can you pass an enum value as command parameter? 回答1: Try this local - is your namespace reference in the XAML 回答2: Also remember that if your enum is inside another class you need to use the + operator. 回答3: You can use property element syntax instead of attribute syntax for this: First 回答4: Also if you want to provide a [

How to convert a Swift enum: String into an Objective-C enum: NSString?

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am having an issue converting this swift enum to Objective-C : public enum ISO8601Format: String { case Year = "yyyy" // 1997 case YearMonth = "yyyy-MM" // 1997-07 case Date = "yyyy-MM-dd" // 1997-07-16 case DateTime = "yyyy-MM-dd'T'HH:mmZ" // 1997-07-16T19:20+01:00 case DateTimeSec = "yyyy-MM-dd'T'HH:mm:ssZ" // 1997-07-16T19:20:30+01:00 case DateTimeMilliSec = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" // 1997-07-16T19:20:30.45+01:00 init(dateString:String) { switch dateString.characters.count { case 4: self = ISO8601Format(rawValue: ISO8601Format.Year

How to annotate enum fields for deserialization using Jackson json

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Jackson 1.6.2 REST web service/Apache Wink How do I annotate an enum field so that Jackson deserializes it? Inner class public enum BooleanField { BOOLEAN_TRUE { public String value() { return "1";} }, BOOLEAN_FALSE { public String value() { return "0";} }, Java Bean/Request object BooleanField locked; public BooleanField getLocked() {return locked;} The Jackson docs state that it can do this via @JsonValue / @JsonCreator but provides no examples (how helpful!). I'm sure they just don't want too many people using their framework so they are

enum values: NSInteger or int?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: tl;dr Version How are the data types of an enum's constants guaranteed to be NSUInteger instead of unsigned int when declaring an enum thusly: enum { NSNullCellType = 0, NSTextCellType = 1, NSImageCellType = 2 }; typedef NSUInteger NSCellType; The typedef to NSUInteger does not appear to be tied to the enum declaration in any way. Full Version I was reading through Apple's 64-Bit Transition Guide for Cocoa for some guidance on enum values and I came away with a question. Here's a (lengthy) quote from the Enumeration Constants section,

SWIG- Convert C++ enum to Python enum

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working to get C++ class enum to python enum using swig. I have the following implementation in example.h file. namespace colors{ enum class Color{ RED = 0, BLUE = 1, GREEN = 2 }; } My Swig interface file is %module api %{ #include "example.h" %} %include "example.h" But after using swig tool the interface provides the following usage import pywarp_example as impl impl.RED The question arise here is that is it possible to access enum like below thats the way we use in python? impl.Color.RED Or impl.Color.RED.value 回答1: Unlike your

Why I can not get .values() from Enum object class?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to create universal method, for any enum object, that will check if enum has specified value name, but as Enum type object I am unnable to use method values(); . Why? Is there any way to get values from an Enum type object? I need method like this to check if value from configuration is a valid string for myEnum.valueOf(String); because if given string will be wrong then it will throw an exception (and I do not want it). I want my method to look like this: public static Boolean enumContains(Enum en, String valueString){ return

Objective C: convert string to enum

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: If I have an enum: typedef enum { SOMETHING , } MyEnum and I have a NSString "SOMETHING", is there a way I can go directly from the string to the ENUM value? I realize I can just make a dictionary to do this, but I'm curious. 回答1: There isn't really a clean way to do this in Objective-C (or C, for that matter). You're going to have to map the enum values to their string counterparts. There are a number of ways you can do this: (1) A dictionary, as you mentioned. (2) A switch statement. (3) An array of string values where each index