




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、C#利用反射簡化給類字段賦值_ 這個例子主要的思路是建立一個類和數(shù)據(jù)庫查詢語句的字段結構是全都的然后利用反射,挺直用數(shù)據(jù)字段名稱進行拼湊,給類對象的字段進行賦值 1.類的定義 namespace CCB_Donet.ClassFolder public class FieldRuleInfo public string gStrFNo; public string gStrFName; public string gStrFLock; public string gStrFCaption; public string gStrFType; public string gStrFMust; pu
2、blic string gStrFMin; public string gStrFMax; public string gStrFDefault; public string gStrFDate; public string gStrFDB; public string gStrFAllow; public string gStrFDisallow; public string gStrFSB; public string gStrFBig; public string gStrFSmall; public string gStrFInputMethod; public string gStr
3、FCHK; public string gStrFRelation; public string gStrFDesc; public string gStrFSecond; public string gStrFQC; public string gStrFException; public string gStrFASupp; public string gStrFYQH; public string gStrFPos; public string gStrFStar; public string gStrFSave; public string gStrFAddress; public s
4、tring gStrFLblColor; public string gStrFIsCheckList; #region 加載字段規(guī)章 private bool m_GetRule() string strSQL = ; DataTable dtGet = null; #if(DEBUG) try #endif if (Common.gIntTypeOrder = 95) strSQL = select A.FNo,A.FName,A.FLock,A.FCaption,A.FType, + A.FMust,A.FMin,A.FMax,A.FDefault,A.FDate,rn + A.FDB,
5、A.FAllow,A.FDisallow,A.FSB,A.FBig,A.FSmall,A.FInputMethod, + A.FCHK,A.FRelation,A.FDesc,A.FSecond,rn + A.FQC,A.FException,A.FASupp,A.FYQH,A.FPos,A.FStar,A.FSave,+ A.FAddress,A.FLblColor,A.FIsCheckList from P_Field_Rule95 A rn + INNER JOIN P_Field_Initial B ON A.FNo=B.FNo rn + where A.FormType=1 AND
6、B.FSection=1 AND + (B.FRegion95=1 OR B.FRegion95=-1) ORDER BY A.FOrder; else strSQL = select A.FNo,A.FName,A.FLock,A.FCaption,A.FType,+ A.FMust,A.FMin,A.FMax,A.FDefault,A.FDate,rn + A.FDB,A.FAllow,A.FDisallow,A.FSB,A.FBig,A.FSmall,+ A.FInputMethod,A.FCHK,A.FRelation,A.FDesc,A.FSecond,rn + A.FQC,A.FE
7、xception,A.FASupp,A.FYQH,A.FPos,A.FStar,+ A.FSave,A.FAddress,A.FLblColor,A.FIsCheckList + from P_Field_Rule A rn + INNER JOIN P_Field_Initial B ON A.FNo=B.FNo rn + where A.FormType= + Common.gIntFormType.ToString() + AND B.FSection=1 AND (B.FRegion= + Common.gIntRegion.ToString() + OR B.FRegion=-1)
8、ORDER BY A.FOrder; dtGet = DB.GetDataTableBySQL(strSQL); if (dtGet.Rows.Count = 0) Common.ShowMessage(字段規(guī)章表沒有數(shù)據(jù),請馬上聯(lián)系軟件工程師!, MessageBoxIcon.Error); return false; /獲得類信息,為下面的反射調(diào)用做預備 Type oType = Type.GetType(CCB_Donet.ClassFolder.FieldRuleInfo); /生成類對象數(shù)組,和數(shù)據(jù)庫記錄個數(shù)是全都的 mMainFieldRule = new FieldRuleInf
9、odtGet.Rows.Count; for (int i = 0; i dtGet.Rows.Count; i+) /這里用法反射動態(tài)為FieldRuleInfo字段賦值數(shù)據(jù) mMainFieldRulei = new FieldRuleInfo(); for (int j = 0; j dtGet.Columns.Count; j+) /這里挺直獵取類的字段名稱,然后把數(shù)據(jù)庫里對應字段的值賦值給它 FieldInfo fieldInfo = oType.GetField(gStr + dtGet.Columnsj.ColumnName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); fieldInfo.SetValue(mMainFieldRulei, dtGet.Rowsij.ToString(); return true; #if(DEBUG) catch
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025非住宅小區(qū)房屋買賣合同樣本
- 遼寧省重點中學協(xié)作校2024-2025學年高二下學期期中考試 化學 PDF版含答案
- 《職業(yè)安全與健康培訓》課件
- 執(zhí)行董事委派協(xié)議書
- 民工加班法律協(xié)議書
- 法官終止調(diào)解協(xié)議書
- 春節(jié)工廠安全協(xié)議書
- 摔倒事故賠償協(xié)議書
- 教學設備捐贈協(xié)議書
- 支部結隊共建協(xié)議書
- 2024年全國職業(yè)院校技能大賽中職組(母嬰照護賽項)考試題庫(含答案)
- 農(nóng)產(chǎn)品電子商務-形考任務三-國開(ZJ)-參考資料
- 2024年代耕代種協(xié)議書模板范本
- 附件7:《號苗報告》
- 12.1發(fā)散思維與聚合思維的方法 課件-高中政治統(tǒng)編版選擇性必修三邏輯與思維
- 感恩母親課件
- 全國青少年信息素養(yǎng)大賽圖形化編程專項測試題及答案
- 國家安全教育高教-第六章堅持以經(jīng)濟安全為基礎
- 水處理藥劑采購項目技術方案(技術方案)
- 期中測試卷-2024-2025學年語文五年級上冊統(tǒng)編版
- 中國兵器人才研究院在線測評題
評論
0/150
提交評論