c# - Generating default values from property when domain object instainciated -


i have domain object called user , usercreateviewmodel.automapper used mapping viewmodel user. working fine. when mapping done see user domain object has values in userid, createdon , modifiedon respectively like

00000000-0000-0000-0000-000000000000 1/1/0001 12:00:00 1/1/0001 12:00:00 

these default values when instainciate user object. cause problem user object can not create guid , dates properties get.

note: don't want hardcode above default values.

is there clean approach solve problem userid, createon , modifedon generated values properties?

i understand problem

usercreateviewmodel

public class usercreateviewmodel {     public string username { get; set; }     public string password { get; set; } } 

user

private guid? _guid; public guid? userid {         {         return (_guid.hasvalue) ? _guid.value : guid.newguid();     }     set     {         _guid = value;     } }  public string username { get; set; } public string password { get; set; }  private datetime? _createdon; public datetime? createdon {         {         return (_createdon.hasvalue) ? _createdon.value : datetime.now;     }     set     {         _createdon = value;     } }  private datetime? _modifiedon; public datetime? modifiedon {         {         return (_modifiedon.hasvalue) ? _modifiedon.value : datetime.now;     }     set     {         _modifiedon = value;     } } 

have @ beforemap , aftermap features of automapper. these might in customizing assignment of default values.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -