欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Green.AgileMapper新增-Green.ObjectPickUper(do到dto對象的默認抽取)

     Green.AgileMapper意在處理領(lǐng)域驅(qū)動開發(fā)中對象之間的Mapper(如果你還不了解Green.AgileMapper,從這里開始Green.AgileMapper開源項目的使用(1) 和Green.AgileMapper項目(2)-新增DO和DTO代碼生成,項目地址:CodePlex http://agilemapper.codeplex.com/),本項目在后期會針對領(lǐng)域建模提供設(shè)計時候支持,利用EF和NHibernate作為底層ORM框架產(chǎn)生自己的領(lǐng)域框架,在設(shè)計時才會采用這些組件。

我們提供的服務(wù)有:做網(wǎng)站、成都做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、北流ssl等。為成百上千企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的北流網(wǎng)站制作公司

    在我們的領(lǐng)域驅(qū)動開發(fā)中,DomainObject(領(lǐng)域?qū)ο螅┦且粋€自然oo對象,存在許多現(xiàn)實世界的關(guān)系關(guān)聯(lián),在我們的View端一個View卻可能需要數(shù)據(jù)并不是所有關(guān)聯(lián)。經(jīng)常除非特殊的UI模式,我們ViewObject往往都會被弱化,而利用Data Transfer Object代替。我們的dto從do抽取大多時候都是將do 單一Object平面化,對于級聯(lián)刪除更新的集合抽取,非級聯(lián)集合放棄。Green.ObjectPickUper就是一種由do抽取dto的實現(xiàn)策略,產(chǎn)生符合Green.AgileMapper 映射規(guī)則的dto對象。對象抽取可能存在多樣性,這里只是實現(xiàn)了默認抽取規(guī)則,可能不能滿足你的需求,你不需要急,因為在這里采用了策略模式來滿足不同抽取算法的需求(ObjectPickUperBase),Green.ObjectPickUper并不依賴Green.AgileMapper你可以自由抽取。

  在Green.ObjectPickUper中利用了CodeDom實現(xiàn)代碼生成,所以可以支持多語言(如果你還不了解CodeDom可以看這里代碼生成技術(shù)-目錄中CodeDom篇)。

Green.AgileMapper新增-Green.ObjectPickUper(do到dto對象的默認抽取)

 

我們看看單元測試看看Green.ObjectPickUper的簡潔書寫:

測試do對象仍是原對象StudentDo,參考CodePlex http://agilemapper.codeplex.com/

  1. [TestMethod]   
  2.       public void ObjectPickUper_GenCode_Test()   
  3.       {   
  4.           ObjectPickUperManager.Instance.IsSOAObject = false;   
  5.           var str = ObjectPickUperManager.Instance.PickUp<StudenDo>("DTO");   
  6.           var str1 = ObjectPickUperManager.Instance.PickUp<ContactWay>("DTO");   
  7.           var str2 = ObjectPickUperManager.Instance.PickUp<KeyValuePair>("DTO");   
  8.  
  9.           Assert.IsTrue(!string.IsNullOrEmpty(str));   
  10.  
  11.           //驗證編譯是否正確  
  12.           CompilerParameters option = new CompilerParameters();   
  13.           option.GenerateExecutable = false;   
  14.           option.GenerateInMemory = true;   
  15.           option.IncludeDebugInformation = false;   
  16.           option.ReferencedAssemblies.Add("System.dll");   
  17.           option.ReferencedAssemblies.Add(typeof(System.Linq.IQueryable).Assembly.Location);   
  18.           option.ReferencedAssemblies.Add(typeof(StudenDo).Assembly.Location);   
  19.           option.ReferencedAssemblies.Add(typeof(Green.AgileMapper.CollectionMappingAttribute).Assembly.Location);   
  20.  
  21.           var result = CodeDomProvider.CreateProvider("c#").CompileAssemblyFromSource(option, str, str1, str2);   
  22.           var assembly = result.CompiledAssembly;   
  23.           Assert.IsFalse(result.Errors.HasErrors, "編譯錯誤");   
  24.       }  

這里采用CodeDom動態(tài)編譯,查看是否存在編譯錯誤。

生成dto:

  1. namespace Green.AgileMapper.Test   
  2. {   
  3.     using System;   
  4.     using System.Collections.Generic;   
  5.     using System.Linq;   
  6.     using System.Text;   
  7.     [System.SerializableAttribute()]   
  8.     public class StudenDoDTO : System.ComponentModel.INotifyPropertyChanged, System.ICloneable   
  9.     {   
  10.         private int _ID;   
  11.         private Green.AgileMapper.Test.Sex _Sex;   
  12.         private System.Collections.Generic.List<System.String> _CourseIds;   
  13.         private string _AddressCountry;   
  14.         private string _AddressProvince;   
  15.         private string _AddressStreet;   
  16.         private string _AddressParticular;   
  17.         private Green.AgileMapper.Test.ContactWayDTO _ContactWay;   
  18.         private System.Collections.Generic.List<Green.AgileMapper.Test.KeyValuePairDTO> _Propertys;   
  19.         public int ID   
  20.         {   
  21.             get   
  22.             {   
  23.                 return this._ID;   
  24.             }   
  25.             set   
  26.             {   
  27.                 if ((this._ID != value))   
  28.                 {   
  29.                     this._ID = value;   
  30.                     this.OnNotifyPropertyChanged("ID");   
  31.                 }   
  32.             }   
  33.         }   
  34.         public Green.AgileMapper.Test.Sex Sex   
  35.         {   
  36.             get   
  37.             {   
  38.                 return this._Sex;   
  39.             }   
  40.             set   
  41.             {   
  42.                 if ((this._Sex != value))   
  43.                 {   
  44.                     this._Sex = value;   
  45.                     this.OnNotifyPropertyChanged("Sex");   
  46.                 }   
  47.             }   
  48.         }   
  49.         [Green.AgileMapper.CollectionMappingAttribute(Name="CourseIds", IsConvertTo=true, IsConvertFrom=true, IsDeleteNotInFromItem=true)]   
  50.         public System.Collections.Generic.List<System.String> CourseIds   
  51.         {   
  52.             get   
  53.             {   
  54.                 return this._CourseIds;   
  55.             }   
  56.             set   
  57.             {   
  58.                 if ((this._CourseIds != value))   
  59.                 {   
  60.                     this._CourseIds = value;   
  61.                     this.OnNotifyPropertyChanged("CourseIds");   
  62.                 }   
  63.             }   
  64.         }   
  65.         [Green.AgileMapper.MappingAttribute(Name="Address.Country", IsConvertTo=true, IsConvertFrom=true)]   
  66.         public string AddressCountry   
  67.         {   
  68.             get   
  69.             {   
  70.                 return this._AddressCountry;   
  71.             }   
  72.             set   
  73.             {   
  74.                 if ((this._AddressCountry != value))   
  75.                 {   
  76.                     this._AddressCountry = value;   
  77.                     this.OnNotifyPropertyChanged("AddressCountry");   
  78.                 }   
  79.             }   
  80.         }   
  81.         [Green.AgileMapper.MappingAttribute(Name="Address.Province", IsConvertTo=true, IsConvertFrom=true)]   
  82.         public string AddressProvince   
  83.         {   
  84.             get   
  85.             {   
  86.                 return this._AddressProvince;   
  87.             }   
  88.             set   
  89.             {   
  90.                 if ((this._AddressProvince != value))   
  91.                 {   
  92.                     this._AddressProvince = value;   
  93.                     this.OnNotifyPropertyChanged("AddressProvince");   
  94.                 }   
  95.             }   
  96.         }   
  97.         [Green.AgileMapper.MappingAttribute(Name="Address.Street", IsConvertTo=true, IsConvertFrom=true)]   
  98.         public string AddressStreet   
  99.         {   
  100.             get   
  101.             {   
  102.                 return this._AddressStreet;   
  103.             }   
  104.             set   
  105.             {   
  106.                 if ((this._AddressStreet != value))   
  107.                 {   
  108.                     this._AddressStreet = value;   
  109.                     this.OnNotifyPropertyChanged("AddressStreet");   
  110.                 }   
  111.             }   
  112.         }   
  113.         [Green.AgileMapper.MappingAttribute(Name="Address.Particular", IsConvertTo=true, IsConvertFrom=true)]   
  114.         public string AddressParticular   
  115.         {   
  116.             get   
  117.             {   
  118.                 return this._AddressParticular;   
  119.             }   
  120.             set   
  121.             {   
  122.                 if ((this._AddressParticular != value))   
  123.                 {   
  124.                     this._AddressParticular = value;   
  125.                     this.OnNotifyPropertyChanged("AddressParticular");   
  126.                 }   
  127.             }   
  128.         }   
  129.         [Green.AgileMapper.ObjectMappingAttribute(Name="ContactWay")]   
  130.         public Green.AgileMapper.Test.ContactWayDTO ContactWay   
  131.         {   
  132.             get   
  133.             {   
  134.                 return this._ContactWay;   
  135.             }   
  136.             set   
  137.             {   
  138.                 if ((this._ContactWay != value))   
  139.                 {   
  140.                     this._ContactWay = value;   
  141.                     this.OnNotifyPropertyChanged("ContactWay");   
  142.                 }   
  143.             }   
  144.         }   
  145.         [Green.AgileMapper.CollectionMappingAttribute(Name="Propertys", IsConvertTo=true, IsConvertFrom=true, IsDeleteNotInFromItem=true, EqualExpression=null)]   
  146.         public System.Collections.Generic.List<Green.AgileMapper.Test.KeyValuePairDTO> Propertys   
  147.         {   
  148.             get   
  149.             {   
  150.                 return this._Propertys;   
  151.             }   
  152.             set   
  153.             {   
  154.                 if ((this._Propertys != value))   
  155.                 {   
  156.                     this._Propertys = value;   
  157.                     this.OnNotifyPropertyChanged("Propertys");   
  158.                 }   
  159.             }   
  160.         }   
  161.         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;   
  162.         public void OnNotifyPropertyChanged(string property)   
  163.         {   
  164.             if ((this.PropertyChanged != null))   
  165.             {   
  166.                 this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(property));   
  167.             }   
  168.         }   
  169.         public object Clone()   
  170.         {   
  171.             StudenDoDTO cloneObj;   
  172.             cloneObj = new StudenDoDTO();   
  173.             cloneObj._ID = this.ID;   
  174.             cloneObj._Sex = this.Sex;   
  175.             System.Collections.Generic.List<System.String> CourseIdsList;   
  176.             CourseIdsList = new System.Collections.Generic.List<System.String>();   
  177.             if ((this.CourseIds != null))   
  178.             {   
  179.                 int i;   
  180.                 for (i = 0; (i < this.CourseIds.Count); i = (i + 1))   
  181.                 {   
  182.                     CourseIdsList.Add(this.CourseIds[i]);   
  183.                 }   
  184.             }   
  185.             cloneObj._CourseIds = CourseIdsList;   
  186.             cloneObj._AddressCountry = this.AddressCountry;   
  187.             cloneObj._AddressProvince = this.AddressProvince;   
  188.             cloneObj._AddressStreet = this.AddressStreet;   
  189.             cloneObj._AddressParticular = this.AddressParticular;   
  190.             cloneObj._ContactWay = ((Green.AgileMapper.Test.ContactWayDTO)(this.ContactWay.Clone()));   
  191.             System.Collections.Generic.List&lt;Green.AgileMapper.Test.KeyValuePairDTO> PropertysList;   
  192.             PropertysList = new System.Collections.Generic.List<Green.AgileMapper.Test.KeyValuePairDTO>();   
  193.             if ((this.Propertys != null))   
  194.             {   
  195.                 int i;   
  196.                 for (i = 0; (i &lt; this.Propertys.Count); i = (i + 1))   
  197.                 {   
  198.                     PropertysList.Add(((Green.AgileMapper.Test.KeyValuePairDTO)(this.Propertys[i].Clone())));   
  199.                 }   
  200.             }   
  201.             cloneObj._Propertys = PropertysList;   
  202.             return cloneObj;   
  203.         }   
  204.     }   
  205. }  
  206.  

源代碼參加:CodePlex http://agilemapper.codeplex.com/

其他相關(guān)博文:

1:Green.AgileMapper開源項目的使用(1)

2:Green.AgileMapper項目(2)-新增DO和DTO代碼生成

3:代碼生成技術(shù)-目錄

文章題目:Green.AgileMapper新增-Green.ObjectPickUper(do到dto對象的默認抽取)
文章網(wǎng)址:http://chinadenli.net/article2/jggcoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊品牌網(wǎng)站建設(shè)網(wǎng)站維護Google服務(wù)器托管品牌網(wǎng)站設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營