Instance references from Shared methods

TerryNewton

New member
Joined
Sep 13, 2006
Messages
2
Programming Experience
Beginner
I am creating quite a number of objects with substantial code associated with them as part of a monolithic desktop application for which many instances of the objects may be present in memory at the same time. I want to reduce the footprint by making the code shared

Since I get
'Me' is only valid within an instance method.
or some similar message that tells me I need a reference to an instance variable I have identified the following sequence as a solution. This is kludgy.

:confused: Does anyone have a better way to work around the lack of a built in reference to the instanced items from the shared logic than this?

VB.NET:
Public Sub x(ByVal DR As DataRow) 
    x(Me, DR)
End Sub
 
Public Shared Sub x(ByVal Instance As ObjClass, ByVal DR As DataRow)
    Instance.property=something'example of a reference that works
    'lots of additional code
End Sub

This defeats the error. ObjClass is simply used to give me tighter typechecking etc. and not meaningful for the example. Datarow is also meaningless except to show how I pass parameters in.
 
Back
Top