468,512 Members | 1,382 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 4702
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by SpaceCowboy | last post: by
2 posts views Thread by Faisal | last post: by
4 posts views Thread by Martin Pritchard | last post: by
1 post views Thread by Harold Hsu | last post: by
3 posts views Thread by lou zion | last post: by
2 posts views Thread by Steven T. Hatton | last post: by
13 posts views Thread by Bob | last post: by
3 posts views Thread by =?Utf-8?B?Sm9uYXRoYW4gU21pdGg=?= | last post: by
3 posts views Thread by Dean Mitchell | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.