Click here to Skip to main content
15,886,919 members

Comments by BHort (Top 31 by date)

BHort 31-Oct-11 11:54am View    
I was thinking something like this might work:

Public Class mystringclass
Private mystring
Public Sub New(curString As String)
mystring = curString
End Sub
Public Function ProcStr() As String
Return somefunkyprocessingon_mystring
End Function
End Class
Public Class MyClass
Private MyStr As mystringclass
Other declarations here as well
Public Sub New(curStr As String, other items)
MyStr = New mystringclass(curStr)
other stuff
End Sub
End Class

I'm fairly new to .Net so would this allow me to have myclass.MyStr.ProcStr?

I know I've left out a lot of the plumbing ... I was trying to focus on just the core components ...
BHort 31-Oct-11 11:45am View    
Ok ... then how can I describe what I want.

I have a class myclass
The class has a string property (one of many properties) mystring
I want to process the string in a standard way but I don't want to give future programmers the impression that the method call is operating on anything other than just that string.
My thinking was that if the method call looked like

myclass.mystring.mymethod

It would be the most obvious that the method was only operating on the string.

I know how to create myclass.mymethod but that doesn't provide the opportunity for self documenting code.

Is there a way to do this or not.
BHort 29-Oct-11 10:04am View    
Ok ... I'm not quite sure how I gave you the impression that I cared if all the standard methods were hidden or not ... I don't care. I just want to be able to have my methods visible ... that's my goal, not hiding a bunch of other stuff.

So if I want myclass.mystring.mymethod to exist and work ... do I need to create a seperate class for mystring or can I create it all within myclass and how would the getter/setter and method be defined?

I tried Public ReadOnly Property MyString() As String but I couldn't figure out how to create the method to work on that rather than being a method for the class as a whole. So this created MyString and it worked but I couldn't figure out the method part of getting this to work as I'm hoping.
BHort 29-Oct-11 8:47am View    
Or explain better.


One of the properties of my class is a string. I want to create a method that works on that string that is called by doing a myclass.mystring.method call rather than simply a myclass.method call.


Does that make it clearer?

So what I was suggesting was that perhaps I needed to create

mystringclass

and within that create mystringclass.method

And then in my outer class I would have myclass.mystringclassobject which would then have a method associated which I could call by doing a myclass.mystringclassobject.method call.

Hopefully this makes some sense ...
BHort 28-Oct-11 14:54pm View    
I tried right after posting my comment. Hence my accepting the solution prior to your response.