473,372 Members | 897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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.Colors ' <- 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
"Presentation layer", "Business layer" and "Data layer".

I do not want the "Presentation 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 "Presentation 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 4915
On Fri, 30 Jan 2004 14:37:07 +0100, M O J O
<mojo@_no_spam_delete_this_newwebsolutions.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.Colors ' <- 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_newwebsolutions.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.Colors ' <- Error
"ClassMaster.Colors" is a type, not a value. You would have to write

Return ClassMaster.Colors.Red

- or, if you want to return the type -

Public ReadOnly Property Colors() As Sytem.Type
Get
Return GetType(ClassMaster.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
"Presentation layer", "Business layer" and "Data layer".

I do not want the "Presentation 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 "Presentation 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_newwebsolutions.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
"Presentation 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.Colors ' <- Error ClassMaster.Colors 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.Colors.Red
End Get
End Property
End Class

Module Main
Public Sub Main()
Dim color As ClassMaster.Colors = ClassMaster.Colors.Green
Dim oCar As New Cars
Console.WriteLine(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_newwebsolutions.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.public.dotnet.languages.vb
NNTP-Posting-Host: 0x503f60c3.virnxx9.adsl.tele.dk 80.63.96.195
Lines: 1
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP10.
phx.gblXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:177509
X-Tomcat-NG: microsoft.public.dotnet.languages.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.Colors ' <- 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
"Presentation layer", "Business layer" and "Data layer".

I do not want the "Presentation 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 "Presentation 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
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...
2
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...
4
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...
1
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
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};...
2
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...
13
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...
3
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
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.