C# - Iterate All Public Enums?
Nov 22, 2010
We have a common component in our source which contains all the enums (approx 300!) for a very large application.Is there any way, using either C# or VB.NET, to iterate through all of them in order to perform an action on each one?
How to iterate all "public string" properties in a .net class is almost relevant but the enums I am dealing with are a mix of types.
View 5 Replies
ADVERTISEMENT
Aug 3, 2011
I thought that enums in VB and C# where the same or at least very similar. Then today I stumbled across a bug in our VB code. The following VB code compiles and runs with no issues:
Enum Cars
Subaru
Volvo
End Enum
[code]....
Why does the VB version not catch the type mismatch? Are enum in VB and C# different?
View 2 Replies
Feb 10, 2011
I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.
View 2 Replies
Apr 7, 2011
Imports System
Imports System.Threading
Imports System.ComponentModel[code]....
how to declare "smsport" on class smscomms as public so that it can be access in class form1 or button1_click event.
View 5 Replies
Aug 26, 2010
How do declare a public variable .aspx web page that can be used in all the pages within my web application?
View 3 Replies
Feb 15, 2010
Until asking a question on here I never considered (enums) to be a "bad thing." For those out there that consider them not to be best practice, what are some approachs/patterns for avoiding their use in code?
Edit:
public Enum SomeStatus
Approved = 1
Denied = 2
Pending =3
end Enum
View 5 Replies
Jan 14, 2010
We have legacy character codes that we want to store as numbers in a new system. To increase readibility and general understanding in the code for devs making the migration, I want to do Enums like this..
[Code]...
With this setup, the code will be readable (imagine If Record.Status = Status.Open), and yet the values will be stored in the database as small numbers so it will be efficient. However... I am a VB.NET guy, but everybody wants to code in C#, so I need this sort of structure in C#.After Googling, I discovered the the general .NET equivalent of AscW is Convert.ToInt32("C"). When I try to use that statement in an enum, I get the compiler error "Constant Expression Required".
View 2 Replies
Oct 4, 2011
I have an enum and a usercontrol, both in the same assembly (a plain .NET 4 web site). In the Constants class:public Enum CrudOperations Add Edit Delete. This controls the columns in a GridView on a UserControl via a property on the UserControl
[Code]...
In C#, I've specified the columns to show with markup as Mode="Edit,Delete", but in VB.NET, this does nothing. The only way I can get anything to show is with the codebehind, but if on the containing page I use userGrid.Mode = CrudOperations.Edit And CrudOperations.Delete, I get all the columns (there's also a delete column), but userGrid.Mode = CrudOperations.Edit Or CrudOperations.Delete shows nothing.
View 1 Replies
Mar 10, 2011
I have a public property, "Status" that is an enum. I have a setter method that changes the status and raises the PropertyChanged event. However, the WinForms user interface is not properly updating. I'm pretty sure it's because Status is an enum. Although I was thinking enum was a reference type but I guess it's a value type. Does INotifyPropertyChanged work the same with reference and value types?
[Code]...
View 3 Replies
Nov 25, 2008
I work for a web hosting company and was handed a VB script which I apparently have to compile with some updated settings by 1 of our clients who knows less about it than I do. But when trying to compile the code I receive an error "'Enums.NoticeType' is not defined". As expected I haven't a clue. Am I missing some of the code, or do I have to add some libraries in my Visual Basic 2008 Express Edition? I have pasted the line of code below. If requested I can provide the whole script.
Code:
Public Function UpdateNotices(ByVal intNoticeID As Integer,
ByVal strNoticeTitle As String, ByVal dtDateFrom As Date, ByVal dtDateTo
As Date, ByVal intTypeID As Enums.NoticeType, ByVal boolPrimaryItem As
Boolean, ByVal boolActive As Boolean) As Int32
View 1 Replies
Oct 20, 2011
I have a solution with multiple projects, some of the projects are written in VB, some in C#. I am wondering if there's a way to use interfaces and/or enums written in VB in C# classes? My C# code below doesn't compile, however I am able to see the interface in intellisense.
[Code]...
P.S It's a console/service application, not ASP.Net (where I know it's doable).UPD: Sorry guys, was missing a reference to the project with the interface. It's fixed now. I think the thing that in VB projects references are done slightly different than in C# confused me.
View 2 Replies
Sep 23, 2010
I have a base class with the the following enum and property:
[Code]...
First off, how do I do this - is it by simply overloading it? And secondly will my original property pick up the new enum automatically when using the derived class or will I need to overload that too?
View 2 Replies
Feb 16, 2012
I'm using LuaInterface for .NET to create Windows Forms objects. This works pretty good except for one thing:I want to use the Anchor property of Control to make them resize automatically. If I only set one of the Anchors (e.g. only AnchorStyles.Top), it works, but this doesn't really make sense. I have to set more than one Anchor, which is done by combining them with "bit-wise or" (or by just adding them numerically).
In VB.Net both works:
Dim myLabel As New Label()
myLabel.Anchor = AnchorStyles.Top[code]....
which is in a sense correct as "LuaInterface treats enumeration values as fields of the corresponding enumeration typ" (says LuaInterface: Scripting the .NET CLR with Lua).It is also not possible to assign the value as a number:
myLabel.Anchor = 15 -- 15 = 8 + 4 + 2 + 1 = Top+Left+Right+Bottom
This time, the error message is rather unspecific:
LuaInterface.LuaException: function
Is there a possibility to typecast the number to the correct enumeration type in Lua?
View 1 Replies
Jan 27, 2010
What would the folowing VB.NET enum definition look like in C#? [code]
View 7 Replies
Apr 16, 2010
Is it guaranteed that the numeric values for an Enum with only uninitialized values start at zero and increment by one in the order defined?
View 2 Replies
Mar 10, 2009
I want to add a setting that uses an enum defined in form1.vb. All the research I've done suggests support for enum type settings is built-in and handled automatically by the VS IDE ... I assume this means it's as easy as defining font or color settings. However, I'm not having much. Are any of you gurus aware of how to set up an enum setting via the Project Settings UI?
View 8 Replies
Jul 22, 2010
I realize this is probably trivial, but for some reason I'm not sure how to pull it off. Say I have the following enum:
Public Enum FlagType
Docs
Email
[Code]....
How do I then at runtime determine which flags where set for flags? In this example, it should be Docs and Email.
View 19 Replies
Jan 9, 2012
Is there a way to use strings in Enums like the example below:
Enum myEnum
val1 = "some string 1"
val2 = "some string 2"
val3 = "some string etc"
End Enum
It seems like you can only use integers for the underlying values.
View 13 Replies
Sep 21, 2009
I am developing a program in VB.NET. I have an enum called PriceType that is declared in a super class ItemPriceBase. There are 3 classes that derive from ItemPriceBase - ItemPriceMeasured, ItemPriceNDI and ItemPriceExtraCost. The subset of PriceTypes for these classes are totally unique from each - Measured prices are 1 to 6, NDI prices are 7 to 15 and ExtraCost prices are 16 to 22.
Is there a way declare the enum in the super class and then extend the enum in each of the derived classes so that they only have access to those options, yet I can still access a property in the super class that returns an enum of PriceType?
View 3 Replies
Oct 13, 2009
Public Enum Fruit
Red_Apple = 1
Oranges
Ripe_Banana
End Enum
Private Sub InitCombosRegular()
[Code]...
Why does the Ctype work and the Directcast does not with the same syntax? Yet if I cast the selectedValue to an int before I DirectCast, then it works
View 1 Replies
Jan 7, 2010
i've got a custom integral type, and i want to be able to
Private Enum ENUM_Stuff As MyInteger
what i want to do: to know if there is anyway to make the above statement valid
View 7 Replies
Aug 21, 2010
I've heard bad things about overusing regions but when adding enums to my classes I put them into a #region "Enums" at the end of the class, and do the same with structures and even subclasses.
Is there a better/standard way to go about grouping such elements on classes?
(Note: this is tagged C#/VB but maybe the same situation exists for other languages, like Java)
View 1 Replies
Jul 10, 2009
I have a flags enumeration property that I need to show in a property grid: [Code] In the property grid however, it only allows me to select a single value. I cannot combine the values like usual in a flags enum. How do I show something like a checked listbox in the property grid, so that the user can combine flags by checking items? A None and All item would be great but not required. [url]
But even that does not work properly. It seems to check and uncheck items arbitrarily. If you check the first and fourth item for example, the second and third items will sometimes be checked too. Yes, I realize that is supposed to happen with the TestEnum property (as that defines 'BottomRight' as 'Bottom Or Right', so that's logical), but it also happens with the SecurityFlags for example, which it shouldn't.
View 2 Replies
Apr 17, 2012
Here's my current set-up:
Public Interface IDatabase
Function CreateParameter(name as String, dbType as <dbTypeEnumeration>)
End Interface
[Code]....
The problem here is what exactly is dbTypeEnumeration. In the example above, it's simply a placeholder to what my problem is. Since we use both Oracle and SQL Server databases, the DbTypes are different depending on the database being used. For Oracle, the OracleClient object has its own OracleDbType enumeration with types. SQL Server also has its own enumeration.
My question is: is it possible to show those database-specific enumerations depending on which repository is injected into the DatabaseService constructor? If not, what's the best way to go about this? I want to separate the two databases, share logic, and allow for future development, ala the interface as a code contract for that development.
View 2 Replies
Jan 19, 2010
I have a table, lets call it Objects. It has a predefined set of records looking like this:
ObjectId ObjectName
1 Salmon
2 Trout
3 Seabass
4 Shark
Etc..
So, this I would like to implement somehow as an enum. But what's the best way, implement it in the database creating tables for it or in the application logic in an CommonEnums codebehind file etc?
View 2 Replies
Jan 27, 2012
I'm using a DynamicJsonModelBinder from a blog post to pass my JSON data from JavaScript to my ASP.NET MVC Controller as a DynamicJsonObject.
Have a look at the blog post: [URL]
I converted it for my project to VB.NET : [URL]
Imports System.Dynamic
Imports System.Web.Helpers
Namespace MyNameSpace
[Code]....
This works. In my controller, I can access my jsonObject like this: obj.ID '123
But I haven't got an idea yet how to iterate through all properties. I can get all member names as a IEnumerable String Collection (obj.GetDynamicMemberNames()), but how do I use the TryGetMember method to access the value of a member ?
View 1 Replies
Aug 15, 2011
I have a VB Web Application with a bunch of textboxes on it in Default.aspx (Using the basic template in Visual Web Designer 2010 Express). I'd like to iterate through those textboxes using some sort of VB solution if at all possible and clear them when the user presses a button. I've tried using something like this:
Dim cControl As Control
For Each cControl in Me.Controls
If cControl Is TextBox Then
[Code].....
View 3 Replies
Jul 7, 2010
[This is a simplified example] I have a collection ("myCollection") in which exists three entries: ("hello", "goodbye", "welcome"). I want to iterate through the collection and if in the collection there is the entry "welcome" I want to take one action, if that entry doesn't exist I want to do something else. Like this (pseudo):
[Code]...
View 1 Replies
Jan 15, 2010
I need some help with a LINQ query in VB.Net, please.[code]This works, and returns me the data I need to work with. Now I want to iterate through the groups, using a For Each construct. like this: For Each x In drivers Next...However, the compiler is barking at me, telling me that the "'x' is not accessible in this context because it is 'Friend'."
View 3 Replies
May 19, 2011
I have a simple XAML file with a grid in it and textboxes. But when using my code it does not find the textboxes by iteration.
VB.Net:
Dim ctl As FrameworkElement = Me.MainWindow
Code:
Dim ChildrenCount As Integer = VisualTreeHelper.GetChildrenCount(ctl)
'ChildrenCount is always zero
For i As Integer = 0 To ChildrenCount - 1
Dim Child As FrameworkElement = VisualTreeHelper.GetChild(ctl, i)
[Code].....
View 3 Replies