Syntax question

  • Thread starter Thread starter Joe Fallon
  • Start date Start date
J

Joe Fallon

When I have a class like the one below I can use Intellisense to get and set
the property.
===========================
Dim mClass as New MyClass
mClass.SomeProp = "joe"
===========================

Public Class MyClass
Private mSomeProp as String

Public Property SomeProp() As String
Get
Return mSomeProp
End Get
Set(ByVal Value As String)
mSomeProp = Value
End Set
End Property

End Class
===========================

I have a method that takes the name of the Property as a String.
mSomeOtherClass.MyMethod("SomeProp")

What I can't figure out is how to get the string "SomeProp" in intellisense.
mClass.SomeProp is going to return "joe" not "SomeProp".

I want to avoid manually looking up the names and typing them if I can
retrieve them using intellsense.
Is this even possible?

Hope that makes some kind of sense.
Any help pointing me in the right direction is appreciated.

Thanks!
 
* "Joe Fallon said:
When I have a class like the one below I can use Intellisense to get and set
the property.
===========================
Dim mClass as New MyClass
mClass.SomeProp = "joe"
===========================

Public Class MyClass
Private mSomeProp as String

Public Property SomeProp() As String
Get
Return mSomeProp
End Get
Set(ByVal Value As String)
mSomeProp = Value
End Set
End Property

End Class
===========================

I have a method that takes the name of the Property as a String.
mSomeOtherClass.MyMethod("SomeProp")

What's the purpose of this method?
What I can't figure out is how to get the string "SomeProp" in intellisense.
mClass.SomeProp is going to return "joe" not "SomeProp".

The code would simply get the property's value, and this value is "joe"
in the sample above.
I want to avoid manually looking up the names and typing them if I can
retrieve them using intellsense.
Is this even possible?

I am not really sure if I understand what you want to archieve, but
maybe you are looking for 'CallByName'.
 
Joe,

I assume what you are trying to do is the same thing I have approached on
field names in data tables.

What I do is in the class is to setup a set of string constants in a class
just for "stong naming". For your example it would be something like the
following class with both the property and the method:

<code (VB.NET) >
Public Class TestClass

''' declare constancts for strong naming
Public Class PropName
Public Shared SomeProp As String = "SomeProp"
End Class

''' declare private property value
Private mSomeProp As String

''' declare public property
Public Property SomeProp() As String
Get
Return mSomeProp
End Get
Set(ByVal Value As String)
mSomeProp = Value
End Set
End Property

''' declare method
Public Sub MyMethod(ByVal PropName As String)

End Sub

End Class
</code>

Now you can access these as you did in your example and notice the method
now uses a "strong name".

<code (VB.NET) >
Dim aClass As New TestClass

aClass.SomeProp = "Joe"

aClass.MyMethod(aClass.PropName.SomeProp)
</code>

This should get you started on how I do this. Since I have to reference
some field names in my applications by the field name text, it works great
and I don't ever misspell the field names.

-Sam Matzen
 
Back
Top