Search Results

Search found 1234 results on 50 pages for 'enum'.

Page 7/50 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • C# Test if an object is an Enum

    - by Aran Mulholland
    I would like to know if 'theObject' is an enum (of any enum type) foreach (var item in Enum.GetValues(theObject.GetType())) { //make sure we have all the enumeration values in the collection if (this.ValuesCollection.Contains(item)) { } else { this.ValuesCollection.Add(item); } Console.WriteLine(item.ToString()); Console.WriteLine(item.GetType().ToString()); }

    Read the article

  • How to store enum values in a NSMutableArray

    - by Oysio
    My problem is since an enum in objective-c essentially is an int value, I am not able to store it in a NSMutableArray. Apparently NSMutableArray won't take any c-date types like an int. Is there any common way to achieve this ? typedef enum { green, blue, red } MyColors; NSMutableArray *list = [[NSMutableArray alloc] initWithObjects: green, blue, red, nil]; //Get enum value back out MyColors greenColor = [list objectAtIndex:0];

    Read the article

  • Creating an enum/class from a Database Table

    - by Mark
    I have a database table that essentially contains different types of things. I'll use animals as an example. I have a table called AnimalTypes: AnimalTypes { ID:int, Name:string } I then populate it with: 1:Dog, 2:Cat, 3:Fish I would like to then have some sort of C# object created that functions similar to this enum be entirely read from the database: enum AnimalTypes { Dog = 1, Cat = 2, Fish = 3 } Is there a way to create an enum/class from a database table as described? I basically want to be able to reference things in the AnimalTypes table using intellisense and AnimalTypes.Dog as an example; I don't actually need an enum, just something that kind of functions like one. Is this possible? Edit: I'm not really that thrilled about generating a DLL as I've seen in other related problems. I feel like this should be possible with reflection.

    Read the article

  • Convert object to enum C#

    - by Shawn Mclean
    I have binded a list of enum to a combobox. Now I want to get the SelectedItem return the enum, which currently returns it as type object. How do I convert this object to my enum? My framework is silverlight on windows-phone-7

    Read the article

  • How to change enum definition without impacting clients using it in C#

    - by Rohit
    I have the following enum defined. I have used underscores as this enum is used in logging and i don't want to incur the overhead of reflection by using custom attribute.We use very heavy logging. Now requirement is to change "LoginFailed_InvalidAttempt1" to "LoginFailed Attempt1". If i change this enum, i will have to change its value across application. I can replace underscore by a space inside logging SP. Is there any way by which i can change this without affecting whole application.Please suggest. public enum ActionType { None, Created, Modified, Activated, Inactivated, Deleted, Login, Logout, ChangePassword, ResetPassword, InvalidPassword, LoginFailed_LockedAccount, LoginFailed_InActiveAccount, LoginFailed_ExpiredAccount, ForgotPassword, LoginFailed_LockedAccount_InvalidAttempts, LoginFailed_InvalidAttempt1, LoginFailed_InvalidAttempt2, LoginFailed_InvalidAttempt3, ForgotPassword_InvalidAttempt1, ForgotPassword_InvalidAttempt2, ForgotPassword_InvalidAttempt3, SessionTimeOut, ForgotPassword_LockedAccount, LockedAccount, ReLogin, ChangePassword_Due_To_Expiration, ChangePassword_AutoExpired }

    Read the article

  • Assign enum property in xaml using silverlight

    - by Malcolm
    I have a property of datattype enum : like public BreakLevel Level { get { return level; } set { level = value; } } And enum defined : public enum BreakLevel { Warning, Fatal } I want bind the neum property to the visibility of my border , somewhat like this: Visibility="{Binding BreakLevel.Fatal}" so is it possible? <Border CornerRadius="4" BorderThickness="1" BorderBrush="#DAE0E5" Visibility="{Binding DataContext.IsError, Converter={StaticResource BoolToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" >

    Read the article

  • Declare java enum with a String array

    - by chama
    I'm trying to declare an enum type based on data that I'm retrieving from a database. I have a method that returns a string array of all the rows in the table that I want to make into an enumerated type. Is there any way to construct an enum with an array? This is what I tried, but from the way it looked in eclipse, it seemed like this just created a method by that name: public enum ConditionCodes{ Condition.getDescriptions(); } Thank you in advance!

    Read the article

  • Best way to create a Unique ID field for an enum

    - by jax
    What is the best way to get a Unique ID from an ENUM that will stay consistent between repeated execution of the program? Currently I am doing this manually by passing an ID to the enum constructor. I don't really want to do this is I can help it. Another option would be to use a static field that gets incremented for each enum value. The problem is that if later I decide to move the enum fields around or delete some this will cause problems with my program as the ID will be saved into user preferences. The ID can be any basic type or a String.

    Read the article

  • 64 bit enum in C++?

    - by Rob
    Is there a way to have a 64 bit enum in C++? Whilst refactoring some code I came across bunch of #defines which would be better as an enum, but being greater than 32 bit causes the compiler to error. For some reason I thought the following might work: enum MY_ENUM : unsigned __int64 { LARGE_VALUE = 0x1000000000000000, };

    Read the article

  • How do you pass an enum by reference?

    - by Darkenor
    I have an enum with four keys I'm taking as input for an interface program and I'd like to pass the enum by value to the interface function, which has become quite long. The enum is like this: enum MYKEYS { W, S, O, L }; There's also a boolean array that I have to pass by reference, which is also a little tricky. bool key[4] = { false, false, false, false }; Does anyone know the proper syntax to pass both of these as reference in a function, similar to: function(int & anintreference);

    Read the article

  • AutoMapper strings to enum descriptions

    - by 6footunder
    Given the requirement: Take an object graph, set all enum type properties based on the processed value of a second string property. Convention dictates that the name of the source string property will be that of the enum property with a postfix of "Raw". By processed we mean we'll need to strip specified characters e.t.c. I've looked at custom formatters, value resolvers and type converters, none of which seems like a solution for this? We want to use AutoMapper as opposed to our own reflection routine for two reasons, a) it's used extensively throughout the rest of the project and b) it gives you recursive traversal ootb. -- Example -- Given the (simple) structure below, and this: var tmp = new SimpleClass { CountryRaw = "United States", Person = new Person { GenderRaw="Male" } }; var tmp2 = new SimpleClass(); Mapper.Map(tmp, tmp2); we'd expect tmp2's MappedCountry enum to be Country.UnitedStates and the Person property to have a gender of Gender.Male. public class SimpleClass1 { public string CountryRaw {get;set;} public Country MappedCountry {get;set;} public Person Person {get;set;} } public class Person { public string GenderRaw {get;set;} public Gender Gender {get;set;} public string Surname {get;set;} } public enum Country { UnitedStates = 1, NewZealand = 2 } public enum Gender { Male, Female, Unknown } Thanks

    Read the article

  • Is switch-case over enumeration bad practice?

    - by Puckl
    I have an enumeration with the commands Play, Stop and Pause for a media player. In two classes I do a switch-case over the received commands. The player runs in a different thread and I deliver the commands in a command queue to the thread. If I generate class diagrams the enumeration has dependencies all over the place. Is there a nicer way to deal with the commands? If I would change/extend the enumeration, I would have to change several classes. (Its not super important to keep the player extensible, but I try to write nice software.)

    Read the article

  • What's the best practice to "look up" Java Enums?

    - by Marcus
    We have a REST API where clients can supply parameters representing values defined on the server in Java Enums. So we can provide a descriptive error, we add this lookup method to each Enum. Seems like we're just copying code (bad). Is there a better practice? public enum MyEnum { A, B, C, D; public static MyEnum lookup(String id) { try { return MyEnum.valueOf(id); } catch (IllegalArgumentException e) { throw new RuntimeException("Invalid value for my enum blah blah: " + id); } } } Update: The default error message provided by valueOf(..) would be No enum const class a.b.c.MyEnum.BadValue. I would like to provide a more descriptive error from the API.

    Read the article

  • MySQL: count enumerated values?

    - by John Isaacks
    If my table looks like this: daily_individual_tracking', 'CREATE TABLE `daily_individual_tracking` ( `daily_individual_tracking_id` int(10) unsigned NOT NULL auto_increment, `daily_individual_tracking_date` date NOT NULL default ''0000-00-00'', `sales` enum(''no'',''yes'') NOT NULL COMMENT ''no'', `repairs` enum(''no'',''yes'') NOT NULL COMMENT ''no'', `shipping` enum(''no'',''yes'') NOT NULL COMMENT ''no'', PRIMARY KEY (`daily_individual_tracking_id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 basically the fields can be either yes or no. How can I count how many yes's their are for each column over a date range? Thanks!!

    Read the article

  • Why don't my groovy enums work, or even compile?

    - by ?????
    I'm running Groovy Version: 1.7.0 JVM: 1.6.0_17 (Update -- I just upgraded to 1.7.1 and get the same errors!) I've tried to use enums, using the exact syntax from the groovy documentation, and each time I see the compile error: Groovy:The class java.lang.Enum refers to the class java.lang.Enum and uses 1 parameters, but the referred class takes no parameters Any ideas on what's going on? For example: This code won't compile or run, and gets the error above. enum VehicleStatus { OFF, IDLING, ACCELERATING, DECELARATING } class Vehicle { Long id Long version VehicleStatus status }

    Read the article

  • Help with enums in Java

    - by devoured elysium
    Is it possible to have an enum change its value (from inside itself)? Maybe it's easier to understand what I mean with code: enum Rate { VeryBad(1), Bad(2), Average(3), Good(4), Excellent(5); private int rate; private Rate(int rate) { this.rate = rate; } public void increateRating() { //is it possible to make the enum variable increase? //this is, if right now this enum has as value Average, after calling this //method to have it change to Good? } } This is want I wanna achieve: Rate rate = Rate.Average; System.out.println(rate); //prints Average; rate.increaseRating(); System.out.println(rate); //prints Good Thanks

    Read the article

  • Selected Item in Dropdown Lists from Enum in ASP.net MVC

    - by AlexCuse
    Sorry if this is a dup, my searching turned up nothing. I am using the following method to generate drop down lists for enum types (lifted from here: http://addinit.com/?q=node/54): public static string DropDownList(this HtmlHelper helper, string name, Type type, object selected) { if (!type.IsEnum) throw new ArgumentException("Type is not an enum."); if(selected != null && selected.GetType() != type) throw new ArgumentException("Selected object is not " + type.ToString()); var enums = new List<SelectListItem>(); foreach (int value in Enum.GetValues(type)) { var item = new SelectListItem(); item.Value = value.ToString(); item.Text = Enum.GetName(type, value); if(selected != null) item.Selected = (int)selected == value; enums.Add(item); } return System.Web.Mvc.Html.SelectExtensions.DropDownList(helper, name, enums, "--Select--"); } It is working fine, except for one thing. If I give the dropdown list the same name as the property on my model the selected value is not set properly. Meaning this works: <%= Html.DropDownList("fam", typeof(EnumFamily), Model.Family)%> But this doesn't: <%= Html.DropDownList("family", typeof(EnumFamily), Model.Family)%> Because I'm trying to pass an entire object directly to the controller method I am posting to, I would really like to have the dropdown list named for the property on the model. When using the "right" name, the dropdown does post correctly, I just can't seem to set the selected value. I don't think this matters but I am running MVC 1 on mono 2.6

    Read the article

  • Enum "does not have a no-arg default constructor" with Jaxb and cxf

    - by Dave
    A client is having an issue running java2ws on some of their code, which uses & extends classes that are consumed from my SOAP web services. Confused yet? :) I'm exposing a SOAP web service (JBoss5, Java 6). Someone is consuming that web service with Axis1 and creating a jar out of it with the data types and client stubs. They are then defining their own type, which extends one of my types. My type contains an enumeration. class MyParent { private MyEnumType myEnum; // getters, settters for myEnum; } class TheirChild extends MyParent { ... } When they are running java2ws on their code (which extends my class), they get Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions net.foo.bar.MyEnuMType does not have a no-arg default constructor. this problem is related to the following location: at net.foo.bar.MyEnumType at public net.foo.bar.MyEnumType net.foo.bar.MyParent.getMyEnum() The enum I've defined is below. This is now how it comes out after being consumed, but it's how I have it defined on the app server: @XmlType(name = "MyEnumType") @XmlEnum public enum MyEnumType { Val1("Val1"), Val2("Val2") private final String value; MyEnumType(String v) { value = v; } public String value() { return value; } public static MyEnumType fromValue(String v) { if (v == null || v.length() == 0) { return null; } if (v.equals("Val1")) { return MyEnumType.Val1; } if (v.equals("Val2")) { return MyEnumType.Val2; } return null; } } I've seen things online and other posts, like (this one) regarding Jaxb's inability to handle Lists or things like that, but I'm baffled about my enum. I'm pretty sure you can't have a default constructor for an enum (well, at least a public no-arg constructor, Java yells at me when I try), so I'm not sure what makes this error possible. Any ideas? Also, the "2 counts of IllegalAnnotationsExceptions" may be because my code actually has two enums that are written similarly, but I left them out of this example for brevity.

    Read the article

  • forward/strong enum in VS2010

    - by Noah Roberts
    At http://blogs.msdn.com/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx there is a table showing C++0x features that are implemented in 2010 RC. Among them are listed forwarding enums and strongly typed enums but they are listed as "partial". The main text of the article says that this means they are either incomplete or implemented in some non-standard way. So I've got VS2010RC and am playing around with the C++0x features. I can't figure these ones out and can't find any documentation on these two features. Not even the simplest attempts compile. enum class E { test }; int main() {} fails with: 1e:\dev_workspace\experimental\2010_feature_assessment\2010_feature_assessment\main.cpp(518): error C2332: 'enum' : missing tag name 1e:\dev_workspace\experimental\2010_feature_assessment\2010_feature_assessment\main.cpp(518): error C2236: unexpected 'class' 'E'. Did you forget a ';'? 1e:\dev_workspace\experimental\2010_feature_assessment\2010_feature_assessment\main.cpp(518): error C3381: 'E' : assembly access specifiers are only available in code compiled with a /clr option 1e:\dev_workspace\experimental\2010_feature_assessment\2010_feature_assessment\main.cpp(518): error C2143: syntax error : missing ';' before '}' 1e:\dev_workspace\experimental\2010_feature_assessment\2010_feature_assessment\main.cpp(518): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== int main() { enum E : short; } Fails with: 1e:\dev_workspace\experimental\2010_feature_assessment\2010_feature_assessment\main.cpp(513): warning C4480: nonstandard extension used: specifying underlying type for enum 'main::E' 1e:\dev_workspace\experimental\2010_feature_assessment\2010_feature_assessment\main.cpp(513): error C2059: syntax error : ';' ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== So it seems it must be some totally non-standard implementation that has allowed them to justify calling this feature "partially" done. How would I rewrite that code to access the forwarding and strong type feature?

    Read the article

  • Trying to convert existing production database table columns from enum to VARCHAR (Rails)

    - by dchua
    Hi everyone, I have a problem that needs me to convert my existing live production (I've duplicated the schema on my local development box, don't worry :)) table column types from enums to a string. Background: Basically, a previous developer left my codebase in absolute shit, migration versions are extremely out of date, and apparently he never used it after a certain point of time in development and now that I'm tasked with migrating a rails 1.2.6 app to 2.3.5, I can't get the tests to run properly on 2.3.5 because my table columns have ENUM column types and they convert to :string, :limit = 0 on my schema.rb which creates the problem of an invalid default value when doing a rake db:test:prepare, like in the case of: Mysql::Error: Invalid default value for 'own_vehicle': CREATE TABLE `lifestyles` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `member_id` int(11) DEFAULT 0 NOT NULL, `own_vehicle` varchar(0) DEFAULT 'Y' NOT NULL, `hobbies` text, `sports` text, `AStar_activities` text, `how_know_IRC` varchar(100), `IRC_referral` varchar(200), `IRC_others` varchar(100), `IRC_rdrive` varchar(30)) ENGINE=InnoDB I'm thinking of writing a migration task that looks through all the database tables for columns with enum and replace it with VARCHAR and I'm wondering if this is the right way to approach this problem. I'm also not very sure how to write it such that it would loop through my database tables and replace all ENUM colum_types with a VARCHAR. References [1] https://rails.lighthouseapp.com/projects/8994/tickets/997-dbschemadump-saves-enum-columns-as-varchar0-on-mysql [2] http://dev.rubyonrails.org/ticket/2832

    Read the article

  • .NET: bool vs enum as a method parameter

    - by Julien Lebosquain
    Each time I'm writing a method that takes a boolean parameter representing an option, I find myself thinking: "should I replace this by an enum which would make reading the method calls much easier?". Consider the following with an object that takes a parameter telling whether the implementation should use its thread-safe version or not (I'm not asking here if this way of doing this is good design or not, only the use of the boolean): public void CreateSomeObject(bool makeThreadSafe); CreateSomeObject(true); When the call is next to the declaration the purpose of the parameter seems of course obvious. When it's in some third party library you barely know, it's harder to immediately see what the code does, compared to: public enum CreationOptions { None, MakeThreadSafe } public void CreateSomeObject(CreationOptions options); CreateSomeObject(CreationOptions.MakeThreadSafe); which describes the intent far better. Things get worse when there's two boolean parameters representing options. See what happened to ObjectContext.SaveChanges(bool) between Framework 3.5 and 4.0. It has been obsoleted because a second option has been introduced and the whole thing has been converted to an enum. While it seems obvious to use an enumeration when there's three elements or more, what's your opinion and experiences about using an enum instead a boolean in these specific cases?

    Read the article

  • how do I use an enum value on a switch statement in C++

    - by BotBotPgm
    I would like to use an enum value for my switch statment in C++. Is it possible to use the enum values enclosed in the "{}" as choices for the "switch()"? I know that switch() needs an integer value in order to direct the flow of programming to the appropriate case number. If this is the case, do I just make a variable for each constant in the 'enum' statment? I also want the user to be able to pick the choice and pass that choice to the switch() statement. for example: cout<< "1 - Easy"; cout<<"2 - Medium"; cout<< "3 -Hard"; enum myChoice {EASY =1 ,MEDIUM = 2, HARD = 3} cin ???? switch(????) case 1/EASY: (can I just type case EAST?) cout << "You picked easy!"; break; case 2/MEDIUM: cout << "You picked medium!"; case 3..... (same thing as case 2 except on hard.) default: return 0; Thanks

    Read the article

  • Enum in WCF RIA Services Object

    - by Blake Blackwell
    Is it possible to have an enum with WCF RIA Services? When I check the generated code for my custom POCO class I don't see the enum property generated. Here is an example of what I'm trying to do: public class Legend { public enum ViewStateType { OnExpanded = 1, OnContracted = 2, OffExpanded = 3, OffContracted = 4 } [Key] public Guid LegendId { get; set; } [EnumDataType(typeof(ViewStateType))] public ViewStateType ViewState { get; set; } } I tried with and without the EnumDataType attribute.

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >