I am working on some VB dot net classes and am inheriting from a class that
has a method that returns a general object. My problem is, of course, is
when i want to return an integer using this method. Ok, so I create a class
to encapsulate the interger as an Object.
Now, my question is how can I now treat that object as an integer? I do not
want the user of my method to have to do this sort of thing:
dim intIntPlusOne as Integer = objInteger.Value + 1
I also wanted to at least provide a default property of the Object so that
object itself acts as an integer, but apparently I can't define a default
property without a parameter.
And of course, now I have to go back and create Object versions of all of my
integers just so they can be passed through this method as an Object. Is
there any better solution out there then the one I have come up with?
In case anyone is interested, here is the method I am working with:
' Note: dtRecord is of type DataTable
Default Public Property FieldValue(ByVal intField As Integer) As Object
Get
If dtRecord Is Nothing Then Return Nothing
Return dtRecord.Rows(0)(intField)
End Get
Set(ByVal Value As Object)
If dtRecord Is Nothing Then Return
dtRecord.Rows(0)(intField) = Value
End Set
End Property
This is a general property for returning a specific column of my DataTable.
Where I am running into problems is where the value of the DataTable column
is an integer.
To elaborate even further... here is a property in my inheriting class that
uses that default property:
ReadOnly Property RecordSID() As Integer
Get
Return Me(FIELDS.RecordSID) ' Note: FIELDS.RecrodSID is the table
index
' Or, for those of you who are lost because of the default property:
' Return Me.FieldValue(FIELDS.RecordSID)
End Get
End Property
See here how this returns an Integer but my general default property returns
an Object? In case you are wondering, I am doing things this way to keep my
common data interactions in an inheritable place.
And, using this method as an example, if I encapsulate the object, I am
trying to avoid this:
dim i as intRecordSID = o.RecordSID.Value
when it currently would be done like this:
dim i as intRecordSID = o.RecordSID
Help!
Thanks,
Joe