Custom Lazy Load Classes

Source: Internet
Author: User

Deferred load class

 Public classLazyloader<tmodel>whereTModel:class{TModel _data; Func<TModel> _loaddatafunc =NULL; BOOL_loaded =false;  PublicLazyloader (): This(NULL){ }         PublicLazyloader (func<tmodel>Loaddatafunc) {_loaddatafunc=Loaddatafunc; _data=NULL; _loaded=false; }         PublicTModel Querydata () {if(!_loaded && _loaddatafunc! =NULL) {_data=_loaddatafunc (); }            return_data; }         Public voidSetData (TModel value) {_data=value; _loaded=true; }}lazyloader

How to use (simply to name a column)

For example, the employee menu might not need to load his menu when you re-use the employee's object. When you want to use it, you need to delay loading it.

 Public classEmployee { PublicLazyloader<ienumerable<menu>>_menus;  PublicEmployee (Guid employeeId,stringEmployeeno,stringNamestringPasswordstringEmailstringPhoneBOOLEnabledBOOLIsadministrtor, DateTime Registerdate,stringRemarkstringiplimitation) {EmployeeId=employeeId; Employeeno=Employeeno; Name=name; Password=password; Email=email; Phone=phone; Enabled=enabled; Isadministrator=Isadministrtor; Registerdate=registerdate; Remark=remark; Iplimitation=iplimitation; _menus=NewLazyloader<ienumerable<menu>> (() =Systemresourceservice.querymenusbyemployeeid (employeeId)); }         PublicGuid EmployeeId {Get;Private Set; }  Public stringEmployeeno {Get;Private Set; }  Public stringName {Get;Private Set; }  Public stringPassword {Get;Private Set; }  Public stringEmail {Get;Private Set; }  Public stringPhone {Get;Private Set; }  Public BOOLEnabled {Get;Set; }  Public BOOLIsadministrator {Get;Private Set; }  PublicDateTime Registerdate {Get;Private Set; }  Public stringRemark {Get;Private Set; }  Public stringiplimitation {Get;Set; }  Public ObjectId {Get{returnEmployeeId;} }}employee

Custom Lazy Load Classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.