enums

How to get the name of an enumeration case by its raw value in Swift 4?

拈花ヽ惹草 提交于 2021-02-20 13:28:08
问题 Using Xcode 9.4.1 and Swift 4.1 Having an enumeration with multiple cases from type Int, how can I print the case name by its rawValue? public enum TestEnum : UInt16{ case ONE = 0x6E71 case TWO = 0x0002 case THREE = 0x0000 } I am accessing the Enum by the rawValue: print("\nCommand Type = 0x" + String(format:"%02X", someObject.getTestEnum.rawValue)) /*this prints: Command Type = 0x6E71 if the given Integer value from someObject.TestEnum is 28273*/ Now I additionally want to print "ONE" after

C# enum to postgres enum

社会主义新天地 提交于 2021-02-19 07:53:45
问题 I am currently using postgres enum CREATE TYPE http_action_enum AS ENUM ('GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'); CREATE TABLE IF NOT EXISTS response ( id UUID PRIMARY KEY, http_action http_action_enum NOT NULL ); But when I using the ef framework to insert to postgres database I keep hit the below error: Exception data: Severity: ERROR SqlState: 42804 MessageText: column "destination" is of type source_dest_enum but expression is of type integer Hint:

C++ enum class: Cast to non existing entry

ⅰ亾dé卋堺 提交于 2021-02-19 04:52:35
问题 I have this situation on one Project where we have some socket-communication that mainly exchanges characters for flow-control. We cast those characters to an enum class : char in a switch. I was wondering, what might happen, if the other end sends an character that is not in our enum class. I have this mwe: enum class Foo : char { UNKNOWN, ENUM1 = 'A', ENUM2 = 'B', ENUM3 = 'C' }; char bar1() { return 'B'; } char bar2() { return 'D'; } int main() { switch((Foo)bar1()) { case Foo::UNKNOWN:std:

WPF Multiple Enum Flags to Converter Parameter?

柔情痞子 提交于 2021-02-19 04:18:38
问题 I have a control which I need visible if an enum value is (A | B | C). I know how to bind the visibility of a control to a SINGLE enum (A) using a converter. How do I go about doing the same for this case? What would go in the parameter? This is the converter I use : public class EnumToVisibilityConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { if ( value == null || parameter == null || !( value

WPF Multiple Enum Flags to Converter Parameter?

感情迁移 提交于 2021-02-19 04:18:37
问题 I have a control which I need visible if an enum value is (A | B | C). I know how to bind the visibility of a control to a SINGLE enum (A) using a converter. How do I go about doing the same for this case? What would go in the parameter? This is the converter I use : public class EnumToVisibilityConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { if ( value == null || parameter == null || !( value

How to map postgresql custom enum column with Slick2.0.1?

橙三吉。 提交于 2021-02-19 02:57:05
问题 I just can't figure it out. What I am using right now is: abstract class DBEnumString extends Enumeration { implicit val enumMapper = MappedJdbcType.base[Value, String]( _.toString(), s => this.withName(s) ) } And then: object SomeEnum extends DBEnumString { type T = Value val A1 = Value("A1") val A2 = Value("A2") } The problem is, during insert/update JDBC driver for PostgreSQL complains about parameter type being "character varying" when column type is "some_enum", which is reasonable as I

WCF Enum By Value Surrogates to support dynamic enums

巧了我就是萌 提交于 2021-02-19 01:37:54
问题 I'm trying to make WCF Support unnamed enums. I've created a Surrogate which works fine when its an enum. However when it's a nullable enum it fails on deserialization. This is my surrogate which was modified from this article, my code differs since I don't want to supply known types: public class EnumValueDataContractSurrogate : IDataContractSurrogate { #region Interface Implementation public Type GetDataContractType(Type type) { return type; } public object GetObjectToSerialize(object obj,

JUnit tests: Suppress enum constructor by mocking?

℡╲_俬逩灬. 提交于 2021-02-18 22:50:33
问题 I know that it is possible to mock a single enum(using How to mock an enum singleton class using Mockito/Powermock?), but I have like 1000 of enum values and they can call 5 different constructors. The enum values are often changing in development. I want to really mock only one or two for my JUnit test. I don't care about the rest, but they are still instantiated, which calls some nasty stuff, which loads the values for the enum from the file system. Yes I know It's very bad design. But for

JUnit tests: Suppress enum constructor by mocking?

一曲冷凌霜 提交于 2021-02-18 22:48:37
问题 I know that it is possible to mock a single enum(using How to mock an enum singleton class using Mockito/Powermock?), but I have like 1000 of enum values and they can call 5 different constructors. The enum values are often changing in development. I want to really mock only one or two for my JUnit test. I don't care about the rest, but they are still instantiated, which calls some nasty stuff, which loads the values for the enum from the file system. Yes I know It's very bad design. But for

Parsing value into nullable enumeration

末鹿安然 提交于 2021-02-18 22:24:29
问题 Let's say I have this: PriorityType? priority; string userInput = ...; I cannot change how this is defined: PriorityType? priority because it's actually part of a contract with another piece of code. I tried this, but it does not work: if (Enum.TryParse<PriorityType?>(userInput, out priority)) { What is the correct way? 回答1: The simplest way: PriorityType tempPriority; PriorityType? priority; if (Enum.TryParse<PriorityType>(userInput, out tempPriority)) priority = tempPriority; This is the