.net - Using VB Interfaces, Enums, Etc In C# Code?

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


ADVERTISEMENT

VS 2008 Interfaces :: Can Contain Code Or Not

Apr 9, 2009

I just started playing around with interfaces recently and I have a couple things I want to ask. First off I always understood that an Interface cannot contain code, you are merely creating almost a "template" of methods, property's etc...Lets say I have this:

Public Class MyTest
Implements IMyTest
Public Sub iDispose() Implements IMyTest.iDispose

[code].....

View 3 Replies

Interfaces - Adding Code To A Sub Or Function

Jan 14, 2010

In using the IDisposable Interface, the two subroutines are displayed in my code from Microsoft when coded. How do I do the same with an Interface that I write? Is it possible or is this a feature that only Microsoft can do? I am using Visual Studio 2005!

View 7 Replies

Enums Error In Vb, How Is It Different From Enums In C#

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

C# - How To Avoid Using Enums

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

Differences Between Enums In C#?

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

Enums Via Markup In .NET?

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

Using Enums With INotifyPropertyChanged?

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

'Enums.NoticeType' Is Not Defined

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

Asp.net - Overloading Enums And Properties In .NET?

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

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

C# - Use Flag-based .NET Enums From Lua?

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

Defining C# Enums With Descriptions

Jan 27, 2010

What would the folowing VB.NET enum definition look like in C#? [code]

View 7 Replies

Enums - .NET Enumeration Representation?

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

Using Enums In Project Settings?

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

VS 2008 Get Assigned Enums With OR?

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

VS 2010 : Using Strings In Enums?

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

Declaring Enums Across Derived Classes

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

Directcast & Ctype Differences With Enums?

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

Enums Can Be Only Declared As Integral Type?

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

C# - How To Group Enums Structures And Subclasses In Classes

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

VS 2008 Flag Enums In Property Grid

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

.net - Handling Different DbType Enums In Database-Agnostic Architecture?

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

SQL - Store Enums At Database Level Or In Application Logic?

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

Are Interfaces Used Often

Oct 16, 2009

Are Interfaces used often? Need opinions.

View 4 Replies

.net - Casting Interfaces And MEF?

Mar 13, 2009

I have the following problem with MEF: Interface definition to be used by host:

Public Interface IExecuteDoSomething
Inherits IAddinSettings
Event DataReceived As EventHandler(Of DataReceivedEventArgs)
Function DoSomething() As Boolean
End Interface

[Code]...

Everything seems to work fine until the Button2_Click routine is executed, then an InvalidCastException is thrown with the info:Unable to cast object of type 'System.Collections.Generic.List1[SharedLibrary.IExecuteDoSomething]' to type 'System.Collections.Generic.List1[SharedLibrary.IAddinSettings]'.

How can i solve this problem, because the imported object implements both of the interfaces?

View 1 Replies

A To Z Usage Of Interfaces In .NET?

Dec 30, 2011

In this discussion let us discuss every usage of interfaces in .NET. Any real time examples and difficulties in using interfaces can also be discussed here.

View 6 Replies

Multiple Interfaces With .NET?

Aug 6, 2009

Im building a game with VB.NET I designed the core of the game in form1 window But now I need menus. How can I implement this without having 5 or so windows that I show() and hide() ? Doing that slows it down a lot and uses lots of memory. I tried tabs, but I don't want the tabs to appear, just switch. Whats the best way to implement multiple interfaces?

View 1 Replies

Oop - Inheritance And Interfaces ?

Jul 14, 2011

Has someone a hint what I'm doing wrong in VB.Net?

Module Module1

Interface ISearch(Of T As ISearchResult)
Function ids() As List(Of T)
End Interface

[CODE]...

The third cast isn't working. Why? did I miss a oop lesson?

View 2 Replies

Using Dictionary With Interfaces?

Sep 12, 2009

What I would like to do is make an abstract class that will hold objects in a dictionary and manage the adding/deleting/key changes of those items in the dictionary. My problem is that in order to make the class as generic as possible I declared the dictionary as dictionary(of long, of SomeInterface).The problem is when I try to pass a strongly typed dictionary in the constructor using dictionary( of long, ClassThatImplementsSomeInterface) I get a compiler error because it cannot convert to that type.

The reason I want to pass the dictionary in the abstract class's constructor is so that I can use the strongly typed dictionary in the subclass and have the abstract class manage the keys when it needs to. So how can I do something like this? Also- If there is a much better way to manage keys than what I am doing feel free to let me know, but I am much more interested in how to make this work since I have encountered this type of problem a few times before.

Here's the abstract class:
Public MustInherit Class HasChildrenKeys
Protected m_childItems As Dictionary(Of Long, IHasKey)

[code].....

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved