T
thechaosengine
Hi all,
I get the following problem crop up every once in a while. I'm wondering
if anyone can tell me how to avoid it because its driving me absolutely insane!
I have a Project class that contains a User property amongst lots of other
properties.
In the Project class's constructor I initialise all the class's parameter
*apart from* the User property. The magic is that at any point after calling
Projects constructor, the User property has also been initialised, when it
should still be null because I've never assigned to it. Indeed I don't want
it to be initialised until I explicitly ask for it
I want to load the User object only when required - aka lazy loading. So
I have the following code:
public User ProjectManager{
get{
if(projectManager != null){
// Initialise the project manager
}
return projectManager;
}
}
Of course, because of the annoying instantiation problem the if statement
always decides that the projectManager variable is not null.
If its any more help, when I look at the initialised User object I can see
in the debugger that it has got all default values for each of its variables.
I've also tried putting a break point in the two user constructors but they
never fire.
This crap never happens with strings and doesnt always happen with custom
classes. Can anyone help as to why this is happening and what I can do to
get my lazy loading working?
Many thanks to anyone who can advise
Kindest Regards
tce
I get the following problem crop up every once in a while. I'm wondering
if anyone can tell me how to avoid it because its driving me absolutely insane!
I have a Project class that contains a User property amongst lots of other
properties.
In the Project class's constructor I initialise all the class's parameter
*apart from* the User property. The magic is that at any point after calling
Projects constructor, the User property has also been initialised, when it
should still be null because I've never assigned to it. Indeed I don't want
it to be initialised until I explicitly ask for it
I want to load the User object only when required - aka lazy loading. So
I have the following code:
public User ProjectManager{
get{
if(projectManager != null){
// Initialise the project manager
}
return projectManager;
}
}
Of course, because of the annoying instantiation problem the if statement
always decides that the projectManager variable is not null.
If its any more help, when I look at the initialised User object I can see
in the debugger that it has got all default values for each of its variables.
I've also tried putting a break point in the two user constructors but they
never fire.
This crap never happens with strings and doesnt always happen with custom
classes. Can anyone help as to why this is happening and what I can do to
get my lazy loading working?
Many thanks to anyone who can advise
Kindest Regards
tce