Thought of solution, but any thoughts would be welcome...
I am curious about how I could know the type of an object I am working with from a base class. It would be nice if VB .Net supported anything like overloadable shared properties or something. But it must be accessible from shared/static, since I have shared data in the classes inheriting this base class that needs to use System.Type to know it's type.
Oh. The language I am using is Visual Basic 2005 .NET for my job. We are currently using templates on the base class, which works fine when the project was small, but loses a lot of the advantages Object Oriented code has (Since a new instance of the base class is made for every sub-class).
Of course, it's obvious that MyType is assigned GetType(SubFoo1 ), then assigned GetType(SubFoo2 ) which then means MyType for both SubFoo1 and SubFoo2 is GetType(SubFoo2 ), which I don't want.
I am curious however if GetType(BaseFoo ).Reflection() would return what I am wanting. But I would still have a problem with that because I need exactly one level of inheritance down, and not two (which in a few places I have).
Hm... This question is kind of silly now that I think of it. From a static level, the base class can never know it's sub-classes like this. I think I am looking for a static map which when given the name of the class I desire, returns the System.Type I am looking for.
I will have to give this more thought, remove this post all together. Any ideas you would have would be helpful though :)
As often heard, I'm an experienced C++ programmer, but Visual Basic + the .NET framework is giving me headaches. I would love to work on this project in another language, but our customer will only accept Visual Basic with 2.0 .Net framework.
I guess the syntax changes the way I think when I program :),
TamusJRoyce
I am curious about how I could know the type of an object I am working with from a base class. It would be nice if VB .Net supported anything like overloadable shared properties or something. But it must be accessible from shared/static, since I have shared data in the classes inheriting this base class that needs to use System.Type to know it's type.
Oh. The language I am using is Visual Basic 2005 .NET for my job. We are currently using templates on the base class, which works fine when the project was small, but loses a lot of the advantages Object Oriented code has (Since a new instance of the base class is made for every sub-class).
Code:
Class BaseFoo
Protected Shared MyType As System.Type = GetType(BaseFoo)
Public Sub PrintBaseType()
MessageBox.Show("Type is: " & MyType.Name, "Debugging")
End Sub
End Class
Class SubFoo1
Inherits BaseFoo
Shared Sub New()
MyType = GetType(SubFoo1)
End Sub
Public Sub PrintType1()
MessageBox.Show("Type is: " & MyType.Name, "Debugging")
End Sub
End Class
Class SubFoo2
Inherits BaseFoo
Shared Sub New()
MyType = GetType(SubFoo2)
End Sub
Public Sub PrintType()
MessageBox.Show("Type is: " & MyType.Name, "Debugging")
End Sub
End Class
Class SubSubFoo3
Inherits SubFoo2
Shared Sub New()
' Do not want MyType any farther down than one level of inheritance
'MyType = GetType(SubFoo2)
End Sub
End Sub
I am curious however if GetType(BaseFoo ).Reflection() would return what I am wanting. But I would still have a problem with that because I need exactly one level of inheritance down, and not two (which in a few places I have).
Hm... This question is kind of silly now that I think of it. From a static level, the base class can never know it's sub-classes like this. I think I am looking for a static map which when given the name of the class I desire, returns the System.Type I am looking for.
I will have to give this more thought, remove this post all together. Any ideas you would have would be helpful though :)
As often heard, I'm an experienced C++ programmer, but Visual Basic + the .NET framework is giving me headaches. I would love to work on this project in another language, but our customer will only accept Visual Basic with 2.0 .Net framework.
I guess the syntax changes the way I think when I program :),
TamusJRoyce