473,385 Members | 1,829 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,385 software developers and data experts.

Exposing properties of a class within a class

Intellisense doesn't sense it, and I get the squiggly error
"Reference to a non-shared member requires an object reference".

Here's the property I want to expose.

Public Class Commands
Property FileName() As String
Get
....
Set
....
End Property
Public Sub New()
FileName = ""
End Sub
End Class

So Commands is a public class, with a publicly exposed property
FileName that is given a value when Commands is instantiated.

But Commands is inside another class.

Public Class Parser
Public Class Commands
....
End Class
Public Sub New()
Dim aCommands As New Commands
End Sub
End Class

So Parser is another public class, that creates an instance of
Commands when it's instantiated. Intellisense even detects that
Commands is a subclass of Parser. However, it doesn't give me any
options after that, and typing in the code manually gives me the
object reference error.

Here's the code in question.

Dim aParser as new Parser
aParser.Commands.FileName = "HelloWorld.txt"

Please can someone help?
--
Cheers, ymt.
Feb 15 '06 #1
6 1932
Yuk Tang <ji********@yahoo.com> wrote in
news:Xn*******************************@130.133.1.4 :

Here's the code in question.

Dim aParser as new Parser
aParser.Commands.FileName = "HelloWorld.txt"

Please can someone help?


I can work around it by creating a differently named property and
setting the property to this instance of Commands, but Parser.Commands
still appears in Intellisense, along with Parser.Command (my new
property). Parser.Commands doesn't allow me to access the FileName,
while Parser.Command does.
--
Cheers, ymt.
Feb 15 '06 #2
"Yuk Tang" <ji********@yahoo.com> schrieb
Intellisense doesn't sense it, and I get the squiggly error
"Reference to a non-shared member requires an object reference".

Here's the property I want to expose.

Public Class Commands
Property FileName() As String
Get
...
Set
...
End Property
Public Sub New()
FileName = ""
End Sub
End Class

So Commands is a public class, with a publicly exposed property
FileName that is given a value when Commands is instantiated.

But Commands is inside another class.

Public Class Parser
Public Class Commands
...
End Class
Public Sub New()
Dim aCommands As New Commands
End Sub
End Class

So Parser is another public class, that creates an instance of
Commands when it's instantiated. Intellisense even detects that
Commands is a subclass of Parser. However, it doesn't give me any
options after that, and typing in the code manually gives me the
object reference error.

Here's the code in question.

Dim aParser as new Parser
aParser.Commands.FileName = "HelloWorld.txt"

Please can someone help?

aCommands is the only variable that references a Commands object. As it's
local, it can not be referenced outside Sub New. In addition, it runs out of
scope after Sub New exits. This would work:
Public Class Parser
Public Class Commands
...
End Class

Public aCommands As New Commands 'or Public Readonly

Public Sub New()
End Sub
End Class
Dim aParser as new Parser
aParser.aCommands.FileName = "HelloWorld.txt"
Whether this model is acceptable depends on factors unknown to me.
Armin

Feb 15 '06 #3
"Armin Zingler" <az*******@freenet.de> wrote in
news:#s**************@TK2MSFTNGP11.phx.gbl:
"Yuk Tang" <ji********@yahoo.com> schrieb

Here's the code in question.

Dim aParser as new Parser
aParser.Commands.FileName = "HelloWorld.txt"

Please can someone help?

aCommands is the only variable that references a Commands object.
As it's local, it can not be referenced outside Sub New. In
addition, it runs out of scope after Sub New exits. This would
work:
Public Class Parser
Public Class Commands
...
End Class

Public aCommands As New Commands 'or Public Readonly

Public Sub New()
End Sub
End Class
Dim aParser as new Parser
aParser.aCommands.FileName = "HelloWorld.txt"
Whether this model is acceptable depends on factors unknown to me.


Thanks, it works.
--
Cheers, ymt.
Feb 15 '06 #4
Yuk Tang <ji********@yahoo.com> wrote in
news:Xn*******************************@130.133.1.4 :
"Armin Zingler" <az*******@freenet.de> wrote in
news:#s**************@TK2MSFTNGP11.phx.gbl:
"Yuk Tang" <ji********@yahoo.com> schrieb

Here's the code in question.

Dim aParser as new Parser
aParser.Commands.FileName = "HelloWorld.txt"

Please can someone help?

aCommands is the only variable that references a Commands object.
As it's local, it can not be referenced outside Sub New. In
addition, it runs out of scope after Sub New exits. This would
work:
Public Class Parser
Public Class Commands
...
End Class

Public aCommands As New Commands 'or Public Readonly

Public Sub New()
End Sub
End Class
Dim aParser as new Parser
aParser.aCommands.FileName = "HelloWorld.txt"
Whether this model is acceptable depends on factors unknown to me.


Thanks, it works.


Sorry to be ungrateful, but is there a way of hiding Commands from
Intellisense after doing this? Since I can't use the FileName
property of Commands, there's no real point in having it pop up, but
if I hide it by making Commands private I won't be able to expose
aCommands.
--
Cheers, ymt.
Feb 15 '06 #5
"Yuk Tang" <ji********@yahoo.com> schrieb
Public Class Parser
Public Class Commands
...
End Class

Public aCommands As New Commands 'or Public Readonly

Public Sub New()
End Sub
End Class
Dim aParser as new Parser
aParser.aCommands.FileName = "HelloWorld.txt"
Whether this model is acceptable depends on factors unknown to
me.


Thanks, it works.


Sorry to be ungrateful, but is there a way of hiding Commands from
Intellisense after doing this? Since I can't use the FileName
property of Commands, there's no real point in having it pop up, but
if I hide it by making Commands private I won't be able to expose
aCommands.


Apply the EditorBrowsableAttribute:

Class outerClass
<EditorBrowsableAttribute(EditorBrowsableState.Nev er)> _
Class innerclass

End Class
End Class

Why is it a problem that intellisense lists 'Commands'? It's a member of the
outer class like aCommands. Before anybody else complains: I wouldn't call
the public variable aCommands, it was only to show how to expose the object.
I'd name it 'Commands' and either name the inner class 'CommandClass', or
don't use a nested class and name it 'ParserCommands'. Personal preference
only.
Armin

Feb 15 '06 #6
"Armin Zingler" <az*******@freenet.de> wrote in
news:OQ**************@TK2MSFTNGP11.phx.gbl:
"Yuk Tang" <ji********@yahoo.com> schrieb

Sorry to be ungrateful, but is there a way of hiding Commands
from Intellisense after doing this? Since I can't use the
FileName property of Commands, there's no real point in having it
pop up, but if I hide it by making Commands private I won't be
able to expose aCommands.
Apply the EditorBrowsableAttribute:

Class outerClass
<EditorBrowsableAttribute(EditorBrowsableState.Nev er)> _
Class innerclass

End Class
End Class


Thanks.

Why is it a problem that intellisense lists 'Commands'? It's a
member of the outer class like aCommands. Before anybody else
complains: I wouldn't call the public variable aCommands, it was
only to show how to expose the object. I'd name it 'Commands' and
either name the inner class 'CommandClass', or don't use a nested
class and name it 'ParserCommands'. Personal preference only.


I did something similar, sort of. I renamed the inner class
aCommands so I could call the outer one Commands. I used nested
classes because I'm new to the OOP thing and hence my design is not
perfect, and also Parser had several distinct uses attached to it,
one of which was what I called Commands.
--
Cheers, ymt.
Feb 15 '06 #7

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

Similar topics

0
by: MeMyselfNDotnet | last post by:
Hi All, Im facing a problem with the COM+ component, will appreciate if u can provide any kind of guidance. My COM+, references a class, lets call it class A. It uses the properties of Class A,...
4
by: Luke Briner | last post by:
My ActiveX Container requires certain properties to be exposed by components - properties that appear under the properties section in the IDL/type library file. C# properties are exposed as...
3
by: FredC | last post by:
How do you make a program's properties and methods availale so that other programs can "connect" to them at design time and then use them at run time?
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
5
by: M O J O | last post by:
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
8
by: Dave A | last post by:
I have a class called 'PrimaryKey' that represents the primary key of a table. PrimaryKeys can only be created and the class only implements .ToString(). The PrimaryKey class internally stores...
3
by: Dave | last post by:
Please - anyone that can help. I am getting confusing results while trying to expose a collection from a web service. I have a webservice in which a web method accepts a collection as a...
1
by: Adam Clauss | last post by:
First, I have ComVisible set to true for the entire assembly. I have (abstract) base class A. There are interfaces IA and IAEvents for accessing properties of this object and exposing events. ...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.