/// <summary> /// 載入中介資料並依指定的資料物件回傳。 /// </summary> /// <typeparam name="TModel">指定回傳的資料物件型別。</typeparam> /// <param name="pi_objSource">待載入的中介資料。</param> /// <returns>載入中介資料的資料物件。</returns> /// <remarks> /// Author: 黃竣祥 /// Time: 2017/09/21 /// History: /// 未提供對應的轉換器就忽略該屬性,避免物件缺少例外。(黃竣祥 2017/10/25) /// DB Object: N/A /// </remarks> public TModel Loading <TModel>(XElement pi_objSource) where TModel : new() { TModel objReturn = new TModel(); DefaultConverter <TModel> objDefaultConverter = new DefaultConverter <TModel>(this); if (pi_objSource != null) { foreach (System.Reflection.PropertyInfo objProperty in objReturn.GetType().GetProperties()) { if (objProperty.CanWrite && this.IsExistPropertyValues(pi_objSource, objProperty)) { string sTagName = string.Empty; TransitDataTagAttribute[] objTags = (TransitDataTagAttribute[])objProperty.GetCustomAttributes(typeof(TransitDataTagAttribute), false); IDataConverter <XElement> objConverter = this.FindConverter(objProperty); if ((objTags != null) && (objTags.Count() > 0)) { sTagName = objTags[0].ImportTag; } if (string.IsNullOrEmpty(sTagName)) { sTagName = objProperty.Name; } if (objConverter != null) { objConverter.Successor = objDefaultConverter; objConverter.SetValue(objReturn, objProperty, pi_objSource.Element(sTagName)); } } } } return(objReturn); }
/// <summary> /// 設定資料物件屬性值。 /// </summary> /// <param name="pi_objContainer">資料物件。</param> /// <param name="pi_objProperty">待設定屬性物件。</param> /// <param name="pi_objValue">待設定內容。</param> /// <remarks> /// Author: 黃竣祥 /// Time: 2017/09/21 /// History: N/A /// DB Object: N/A /// </remarks> public override void SetValue(object pi_objContainer, PropertyInfo pi_objProperty, XElement pi_objValue) { TModel objValue = new TModel(); IDataConverter <XElement> objConverter = this.l_objAdapter.GetConverter(pi_objProperty); foreach (System.Reflection.PropertyInfo objProperty in objValue.GetType().GetProperties()) { if (objProperty.Name == pi_objProperty.Name) { objConverter.Successor = new EmptyConverter(); objConverter.SetValue(pi_objContainer, pi_objProperty, objConverter.Export(objValue, objProperty)); break; } } }