.net - How do I lazy load a property? -
i have poco class built through service. hit service info, dto , use build parts of object. i'm trying lazy load of bigger properties they're filled on demand. thought way it:
private list<user> _directreports; public list<user>directreports { { if (this._directreports == null) { setdirectreports(); } return this._directreports; } private set { this._directreports = value; } } private void setdirectreports() { using (var client = new adsclient()) { this._directreports = client.getdirectreports(this.guid); } }
here's problem, , maybe i'm chasing ghosts, when step through debugger , @ guts of object after instantiating it, fields have information in it, , shouldn't @ stage , defeats purpose of i'm trying do. i'm trying understand this, doing wrong? compiler running method point i'm not thinking about?
this debugger artifact. when use watch or quick inspect @ property, debugger run property getter can display value. causes lazy init code execute. you'll never see property return null.
something keep in mind.
Comments
Post a Comment