enumeration

Deserialize json character as enumeration

泄露秘密 提交于 2020-02-19 07:30:06
问题 I have an enumeration defined with C#, where I'm storing it's values as characters, like this: public enum CardType { Artist = 'A', Contemporary = 'C', Historical = 'H', Musician = 'M', Sports = 'S', Writer = 'W' } I'm attempting to deserialize using JSON.NET, but the incoming JSON was written using the CHAR value (string) instead of the int value of the enumeration, like this: [{"CardType","A"},{"CardType", "C"}] Is it possible to define some kind of converter that will allow me to manually

Deserialize json character as enumeration

点点圈 提交于 2020-02-19 07:29:49
问题 I have an enumeration defined with C#, where I'm storing it's values as characters, like this: public enum CardType { Artist = 'A', Contemporary = 'C', Historical = 'H', Musician = 'M', Sports = 'S', Writer = 'W' } I'm attempting to deserialize using JSON.NET, but the incoming JSON was written using the CHAR value (string) instead of the int value of the enumeration, like this: [{"CardType","A"},{"CardType", "C"}] Is it possible to define some kind of converter that will allow me to manually

Listing all possible values for SOAP enumeration with Python SUDS

南楼画角 提交于 2020-01-24 09:57:25
问题 I'm connecting with a SUDS client to a SOAP Server whose wsdl contains many enumerations like the following: </simpleType> <simpleType name="FOOENUMERATION"> <restriction base="xsd:string"> <enumeration value="ALPHA"><!-- enum const = 0 --> <enumeration value="BETA"/><!-- enum const = 1 --> <enumeration value="GAMMA"/><!-- enum const = 2 --> <enumeration value="DELTA"/><!-- enum const = 3 --> </restriction> </simpleType> In my client I am receiving sequences which contain elements of these

Avoid Collection has been modified error

别来无恙 提交于 2020-01-15 07:15:23
问题 Issue: I have the following code: foreach(var ItemA in GenericListInstanceB) { ItemA.MethodThatCouldRemoveAnyItemInGenericListInstanceB(); } Obviously i get an error. What i want to do is change GenericListInstanceB to a class i create, that keeps track of items it should remove. Then, when the loop is finished, it removes them all. Same with adding items. This is fine, i can create a class that has an internal list, and a list of items to add and items to remove. Then another method called

Get an Enumeration (for the Keys) of a Map (HashMap) in Java?

倖福魔咒の 提交于 2020-01-11 22:46:33
问题 As far as I understand this, it seems that there is not a direct way of getting an Enumeration directly for the Keys of a HashMap . I can only get a keySet() . From that Set , I can get an Iterator but an Iterator seems to be something different than an Enumeration . What is the best and most performant way to directly get an Enumeration from the Keys of a HashMap ? Background: I am implementing my own ResourceBundle (=> getKeys() Method), and I have to provide/implement a method that returns

Enumerate members of a structure?

点点圈 提交于 2020-01-11 05:29:16
问题 Is there a way to enumerate the members of a structure (struct | class) in C++ or C? I need to get the member name, type, and value. I've used the following sample code before on a small project where the variables were globally scoped. The problem I have now is that a set of values need to be copied from the GUI to an object, file, and VM environment. I could create another "poor man’s" reflection system or hopefully something better that I haven't thought of yet. Does anyone have any

Enumeration and mapping with Scala 2.10

好久不见. 提交于 2020-01-10 05:13:33
问题 I'm trying to port my application to Scala 2.10.0-M2. I'm seeing some nice improvements with better warnings from compiler. But I also got bunch of errors, all related to me mapping from Enumeration.values . I'll give you a simple example. I'd like to have an enumeration and then pre-create bunch of objects and build a map that uses enumeration values as keys and then some matching objects as values. For example: object Phrase extends Enumeration { type Phrase = Value val PHRASE1 = Value("My

Collection was modified; enumeration operation may not execute in ArrayList [duplicate]

谁都会走 提交于 2020-01-08 11:25:41
问题 This question already has answers here : How to remove elements from a generic list while iterating over it? (26 answers) Closed 6 years ago . I'm trying to remove an item from an ArrayList and I get this Exception: Collection was modified; enumeration operation may not execute. Any ideas? 回答1: You are removing the item during a foreach , yes? Simply, you can't. There are a few common options here: use List<T> and RemoveAll with a predicate iterate backwards by index, removing matching items

Convert between nullable int and int

若如初见. 提交于 2020-01-05 10:26:10
问题 I would like to do something like this : int? l = lc.HasValue ? (int)lc.Value : null; where lc is a nullable enumeration type, say EMyEnumeration?. So I want to test if lc has a value, so if then give its int value to l, otherwise l is null. But when I do this, C# complains that 'Error type of conditional expression cannot be determined as there is no implicit conversion between 'int' and ''. How can I make it correct? Thanks in advance!! 回答1: You have to cast null as well: int? l = lc

How to populate memtables from enumarations?

大憨熊 提交于 2020-01-05 08:50:14
问题 I use memtables to wire enumerated type with comboboxes using LiveBinding. However I have a lot of them and they way I am doing is way too bad (copy/paste) For example, I have the following enumeration: TEnumResourceType = (trtApp, trtTab, trtSection, trtField, trtCommand, trtOther); and for that I created a function to give the string equivalent: function EnumResourceTypeToStr(AEnum: TNaharEnumResourceType): string; begin case AEnum of trtApp : result := 'Aplicação'; trtTab : result :=