473,770 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exposing enums from another class?

Hi,

I want to expose a enum from another class, is that possible and how?

Here's an example
Public Class ClassMaster

Public Enum Colors
Red
Green
Yellow
End Enum

End Class
Public Class Cars

Public ReadOnly Property Colors() As System.Enum
Get
Return ClassMaster.Col ors ' <- Error
End Get
End Property

End Class
Module Main

Public Sub Main()
Private color As Cars.Colors ' <- Error
End Sub

End Module
I know I can make the Enum global by putting it in a module, but I want
to expose it from another class.

I'm creating an application using three layer style, that is
"Presentati on layer", "Business layer" and "Data layer".

I do not want the "Presentati on layer" to reference the "Data layer".
They must know nothing about each others.

All communication to the "Data layer" must go through the "Business layer".

I have an enum in the "Data layer" which I want the "Presentati on layer"
to use, but it must go through the "Business layer".

Hope you get what I mean.

Any idea?

Thanks!

M O J O

Nov 20 '05 #1
5 4935
On Fri, 30 Jan 2004 14:37:07 +0100, M O J O
<mojo@_no_spam_ delete_this_new websolutions.dk > wrote:

----- begin ClassMaster.vb -----
Public Enum Colors
Red
Green
Yellow
End Enum

Public Class ClassMaster
'bla-bla
End Class

Public Class Cars

Public ReadOnly Property Colors() As System.Enum
Get
Return ClassMaster.Col ors ' <- Error
End Get
End Property

End Class
Module Main

Public Sub Main()
Private color As Cars.Colors ' <- Error
End Sub

End Module

------------ Now read here :)
You must declare an enum at the global section of the class, before you
begin the "Public Class" construction. AFAIC it works...

--
.... blood, sugar, sex, magic ...
CIA = Caught In Action programmer
Nov 20 '05 #2
"M O J O" <mojo@_no_spam_ delete_this_new websolutions.dk > schrieb
Hi,

I want to expose a enum from another class, is that possible and
how?

Here's an example
Public Class ClassMaster

Public Enum Colors
Red
Green
Yellow
End Enum

End Class
Public Class Cars

Public ReadOnly Property Colors() As System.Enum
Get
Return ClassMaster.Col ors ' <- Error
"ClassMaster.Co lors" is a type, not a value. You would have to write

Return ClassMaster.Col ors.Red

- or, if you want to return the type -

Public ReadOnly Property Colors() As Sytem.Type
Get
Return GetType(ClassMa ster.Colors)

End Get
End Property

End Class
Module Main

Public Sub Main()
Private color As Cars.Colors ' <- Error
End Sub

End Module
I know I can make the Enum global by putting it in a module, but I want
to expose it from another class.

I'm creating an application using three layer style, that is
"Presentati on layer", "Business layer" and "Data layer".

I do not want the "Presentati on layer" to reference the "Data layer".
They must know nothing about each others.

All communication to the "Data layer" must go through the "Business layer".
I have an enum in the "Data layer" which I want the "Presentati on layer"
to use, but it must go through the "Business layer".

Hope you get what I mean.

I think I do, but where is the problem in exposing the "data layer" types?
If you don't want to do it, you'd have to write wrapper classes within the
business layer for all items in the data layer that you want to use in the
presentation layer.
How is this problem related to the Enum problem?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* M O J O <mojo@_no_spam_ delete_this_new websolutions.dk > scripsit:
I want to expose a enum from another class, is that possible and how? [...]
I know I can make the Enum global by putting it in a module, but I
want to expose it from another class.

I'm creating an application using three layer style, that is
"Presentati on layer", "Business layer" and "Data layer".


You may want to put the enum into a separate namespace, but I don't see
the sense of doing that.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Hi M O J O,

Thanks for posting in the community.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.
Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 20 '05 #5
Hi Mojo,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to use an Enum type
defined in a class and encounter error.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I agree with Armin's suggestion.
Return ClassMaster.Col ors ' <- Error ClassMaster.Col ors is not a type, you may need to return an variable .
Private color As Cars.Colors ' <- Error Cars.Colors is a property not a type. Also you should define a local
variable with private.

Here I change your code as follows.

Public Class ClassMaster
Public Enum Colors
Red
Green
Yellow
End Enum
End Class

Public Class Cars
Public ReadOnly Property Colors() As System.Enum
Get
Return ClassMaster.Col ors.Red
End Get
End Property
End Class

Module Main
Public Sub Main()
Dim color As ClassMaster.Col ors = ClassMaster.Col ors.Green
Dim oCar As New Cars
Console.WriteLi ne(oCar.Colors)
End Sub
End Module

If you have any concern on this issue,please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------Date: Fri, 30 Jan 2004 14:37:07 +0100
From: M O J O <mojo@_no_spam_ delete_this_new websolutions.dk >
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)X-Accept-Language: en-us, en
MIME-Version: 1.0
Subject: Exposing enums from another class?
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <O$************ **@TK2MSFTNGP10 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 0x503f60c3.virn xx9.adsl.tele.d k 80.63.96.195
Lines: 1
Path: cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!TK2 MSFTNGP08.phx.g bl!TK2MSFTNGP10 .
phx.gblXref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:177509
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Hi,

I want to expose a enum from another class, is that possible and how?

Here's an example
Public Class ClassMaster

Public Enum Colors
Red
Green
Yellow
End Enum

End Class
Public Class Cars

Public ReadOnly Property Colors() As System.Enum
Get
Return ClassMaster.Col ors ' <- Error
End Get
End Property

End Class
Module Main

Public Sub Main()
Private color As Cars.Colors ' <- Error
End Sub

End Module
I know I can make the Enum global by putting it in a module, but I want
to expose it from another class.

I'm creating an application using three layer style, that is
"Presentatio n layer", "Business layer" and "Data layer".

I do not want the "Presentati on layer" to reference the "Data layer".
They must know nothing about each others.

All communication to the "Data layer" must go through the "Business layer".

I have an enum in the "Data layer" which I want the "Presentati on layer"
to use, but it must go through the "Business layer".

Hope you get what I mean.

Any idea?

Thanks!

M O J O


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
9554
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could change and lead to memory corruption. I didn't see how this was possible. He claims that if a dll built for a program is built with different compiler settings than the launcher program, the enum size could change. The only way I could figure...
2
2081
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't seem to find an appropriate Reflection method to access Enums within a class I would like to loop through the Enums in the 'Foo' Class retrieve the Enums 'Car' and 'House Public Class Fo Public Enum Ca For Chevrole Toyot
4
5592
by: Martin Pritchard | last post by:
Hi, I'm working on a project that historically contains around 40 enums. In the database various fields refer to the int values of these enums, but of course ref integrity is not enofrced and when looking at the db we can't tell what the value in a field represents. The other problem is that our enums are currently all stored in a single class, which means that because of no visibility constraints the enums are often used out of context...
1
2102
by: Harold Hsu | last post by:
Hi, Originally, I have defined the following Enum within a namespace (outside a class): Public Enum UserRole Admin Manager User End Enum
3
1661
by: lou zion | last post by:
hi all, i'm trying to use a classes enums in another class, but can't seem to find the right syntax. i've got class A which has: enum EditTypeA {Currency, Percent, LabeledNumber, Text}; EditTypeA LineType; // LineType holds widget type, and will be either Currency, Percent, LabeledNumber or Text
2
2784
by: Steven T. Hatton | last post by:
This is not a big deal. It just bothers me that I don't see a way around including the header for QVariant in the following: #ifndef _XML_IMPL_INTERNAL_H_ #define _XML_IMPL_INTERNAL_H_ class QString; class QVariant; namespace xml_impl {
13
5013
by: Bob | last post by:
Hi, Can someone explain why you can't declare enums in an interface? The compiler says "interfaces can't declare types" Ignoring the syntax implications it seems to me that you should be able to declare that an enum exists. i.e. It is within the 'spirit' of an interface to state that it exists. The implementing class will provide the members. e.g. I have a code library that performs a function. It exposes two interfaces which allow for...
3
1561
by: =?Utf-8?B?Sm9uYXRoYW4gU21pdGg=?= | last post by:
I have a class as follows: class GamesConsole { public int iReference; public enum Maker {Nintendo, Sega, Sony, Panasonic} }
3
8006
by: Dean Mitchell | last post by:
Hi everyone, We have a c++ server application that we are writing a GUI client application for. To save our time and to avoid duplicating all the code and functionality that already exists in c++ classes I am building a managed c++ assembly around these classes so that a c# program can use them. The problem is that alot of these c++ classes use enums, I would like to make these visible to the c# application but I cannot find a way to...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.