enum

Is it possible to create a generic Int-to-Enum Converter?

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'd like to be able to say <DataTrigger Binding="{Binding SomeIntValue}" Value="{x:Static local:MyEnum.SomeValue}"> and to have it resolve as True if the int value is equal to (int)MyEnum.Value I know I could make a Converter that returns (MyEnum)intValue , however then I'd have to make a converter for every Enum type I use in my DataTriggers. Is there a generic way to create a converter that would give me this kind of functionality? 回答1: It is possible to create a converter between enum values and their underlying integral types in a

How to extend Python Enum?

匿名 (未验证) 提交于 2019-12-03 02:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is best practice for extending Enum type in Python 3.4 and is there even a possibility for do this? For example: from enum import Enum class EventStatus(Enum): success = 0 failure = 1 class BookingStatus(EventStatus): duplicate = 2 unknown = 3 Traceback (most recent call last): ... TypeError: Cannot extend enumerations Currently there is no possible way to create a base enum class with members and use it in other enum classes (like in the example above). Is there any other way to implement inheritance for Python enums? 回答1: Subclassing

Compiler error: “class, interface, or enum expected”

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have been troubleshooting this program for hours, trying several configurations, and have had no luck. It has been written in java, and has 33 errors (lowered from 50 before) Source Code: /*This program is named derivativeQuiz.java, stored on a network drive I have permission to edit The actual code starts below this line (with the first import statement) */ import java.util.Random; import java.Math.*; import javax.swing.JOptionPane; public static void derivativeQuiz(String args[]) { // a bunch of code } The error log (compiled in JCreator

Why does an @objc enum have a different description than a pure Swift enum?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Consider two Swift enums: enum Foo: Int { case bar } @objc enum Baz: Int { case qux } If I were to print each case of these enums, I would expect the same result. Instead, I see something unexpected: print(Foo.bar) // "bar\n" print(Baz.qux) // "Baz\n" Why does printing a case of an @objc enum print the enum name, while printing the case of a pure Swift enum print the actual case name? Does adding @objc change the debug description of the enum? 回答1: That is because @objc enums are "C-compatible enums", which intentionally do not emit any

Swift enum raw value: not working with CGFloat = -1.0

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What does this not work? enum Aspect : CGFloat { case Clockwise = 1.0 case Anticlockwise = -1.0 } On Anticlockwise line I'm told that 'raw value for enum case must be a literal' 回答1: That sounds like a bug. However it seems to work if you omit the decimal part: enum Aspect : CGFloat { case Clockwise = 1 case Anticlockwise = -1 } 回答2: The weird thing is that a float with a minus is not a literal, but an expression. So the error message is correct. From the Swift programming language: Unlike with integer literals, negative floating-point

MVC 2 - Passing enum to CheckBoxFor

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's assume we have a model: public class Document { public string Name { get; set;} public List<DayOfWeek> WeekDays { get; set; } } Is it possible to render checkboxes that represent days of week for that model? I've searched the internet but did not find any solution. I mean it works whith CheckBoxFor(model=> model.SomeProperty) but it does not work if SomeProperty is List<DayOfWeek> . DayOfWeek here is an enumeration. Thanks in advance. 回答1: You can enumerate on the values of the enum and manually create the checkboxes. Using the same

Getting the max value of an enum

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do you get the max value of an enum? 回答1: Enum.GetValues() seems to return the values in order, so you can do something like this: // given this enum: public enum Foo { Fizz = 3, Bar = 1, Bang = 2 } // this gets Fizz var lastFoo = Enum.GetValues(typeof(Foo)).Cast<Foo>().Last(); Edit For those not willing to read through the comments: You can also do it this way: var lastFoo = Enum.GetValues(typeof(Foo)).Cast<Foo>().Max(); ... which will work when some of your enum values are negative. 回答2: I agree with Matt's answer. If you need just min

Java enum inheritance [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Possible Duplicate: add values to enum Why enums in Java cannot inherit from other enums? Why is this implemented this way? 回答1: Example stolen from here Because adding elements to an enum would effectively create a super class, not a sub class. Consider: enum First {One, Two} enum Second extends First {Three, Four} First a = Second.Four; // clearly illegal Second a = First.One; // should work This is the reverse of the way it works with regular classes. I guess it could be implemented that way but it would be more complicated to implement

Get the name of Enum value

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to make a function where we can get the Namevalue of a EnumValue For example: Get_Enum_ValueName(DayOfWeek, 0) ...This will return " Sunday ". But my code don't works, it says the type is not defined: Private Function Get_Enum_ValueName(Of T)(ByVal EnumName As T, ByVal EnumValue As Integer) As String Return DirectCast([Enum].Parse(GetType(EnumName), EnumValue ), EnumName).ToString End Function 回答1: Given an enum public enum Week { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } here are the things you can do:

How to check if any flags of a flag combination are set?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I have this enum: [Flags] enum Letters { A = 1, B = 2, C = 4, AB = A | B, All = A | B | C, } To check if for example AB is set I can do this: if((letter & Letters.AB) == Letters.AB) Is there a simpler way to check if any of the flags of a combined flag constant are set than the following? if((letter & Letters.A) == Letters.A || (letter & Letters.B) == Letters.B) Could you for example swap the & with something? Not too stable when it comes to binary stuff like this... 回答1: If you want to know if letter has any of the letters in AB