racka
asked on
VB.NET implicitly instantiating objects
I have a class Application, which has a collection containing Applicants attached to it.
In the property for the collection, I have the following:
Get
If _Applicants is Nothing then
_Applicants = new ObjectCollection
LoadApplicants()
End IF
End Get
Now, when I create an Application, I don't make any sort of reference to the Applicant collection, and immediately after the Application is created, in the Quick Watch window I can see that _Applicants is still nothing. The problem starts in the loop below:
For each objApplicant in objApplication.Applicants
....do some stuff
Next
If I set a break point on the "for each" line, then use the watch to check, _Applicants has been instantiated. However, because it hasn't gone through the property, the Applicants haven't been loaded and I never get inside the loop.
Is there anything I can do to stop .NET implicitly creating the Applicants collection, or force it to do so via the property?
In the property for the collection, I have the following:
Get
If _Applicants is Nothing then
_Applicants = new ObjectCollection
LoadApplicants()
End IF
End Get
Now, when I create an Application, I don't make any sort of reference to the Applicant collection, and immediately after the Application is created, in the Quick Watch window I can see that _Applicants is still nothing. The problem starts in the loop below:
For each objApplicant in objApplication.Applicants
....do some stuff
Next
If I set a break point on the "for each" line, then use the watch to check, _Applicants has been instantiated. However, because it hasn't gone through the property, the Applicants haven't been loaded and I never get inside the loop.
Is there anything I can do to stop .NET implicitly creating the Applicants collection, or force it to do so via the property?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.