コード例 #1
0
        /// <summary>
        /// 匯出傳入物件為 XElement 資料型態。
        /// </summary>
        /// <typeparam name="TModel">待匯出資料物件型別。</typeparam>
        /// <param name="pi_objSource">待匯出資料的資料物件。</param>
        /// <returns>匯出資料物件的中介資料。</returns>
        /// <remarks>
        /// Author: 黃竣祥
        /// Time: 2017/09/21
        /// History: N/A
        ///     未提供對應的轉換器就忽略該屬性,避免物件缺少例外。(黃竣祥 2017/10/25)
        /// DB Object: N/A
        /// </remarks>
        private XElement ExportToXElement <TModel>(TModel pi_objSource)
        {
            XElement       objRoot           = new XElement("Root");
            EmptyConverter objEmptyConverter = new EmptyConverter();

            foreach (System.Reflection.PropertyInfo objProperty in pi_objSource.GetType().GetProperties())
            {
                if (objProperty.CanRead)
                {
                    XElement objChild = null;
                    IDataConverter <XElement> objConverter = this.FindConverter(objProperty);

                    if (objConverter != null)
                    {
                        objConverter.Successor = objEmptyConverter;
                        objChild = objConverter.Export(pi_objSource, objProperty);
                        if (objChild != null)
                        {
                            objRoot.Add(objChild);
                        }
                    }
                }
            }
            return(objRoot);
        }
コード例 #2
0
        /// <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;
                }
            }
        }