C 反射賦值

2022-02-25 13:34:44 字數 1806 閱讀 4107

tb_projects model = new

tb_projects();

model.ownerid = 123

;

string fieldname = "

ownerid

";//

欄位名稱

string value = "

333"

; type t =model.gettype();

var p =t.getproperty(fieldname);

if (!p.propertytype.isgenerictype)

else

else

}console.writeline(model.ownerid);

console.readline();

public

class

tb_projects

public

string projectname

//////

編碼

/// public

string projectcode

public

int parentid

public

int? nextid

public

int? projectorder

public

int isenabled

//////

業主單位id

/// public

int? ownerid

//////

施工單位id

/// public

int? constructionid

//////

監理單位id

/// public

int? supervisionid

//////

承包單位id

/// public

int? contractid

//////

第幾級(即在樹層次中第幾級,根元素級次為1,以此類推)

/// public

int? level

//////

數量

/// public

int? quantity

public

int versioning

//////

里程樁號

/// public

string mileageno

//////

標準編碼

/// public

string componentcode

//////

內部編碼

/// public

string ncomponentcode

//////

流程狀態

/// public

int taskstatus

public

string fbxid

//////

判斷是否為單位工程

/// public

int issubunit

//////

所屬標段

/// public

string bidsion

}

view code

java反射 4 反射賦值

本篇介紹利用反射給物件賦值 方法1 獲得並使用預設構造器建立類的物件 並對物件賦值 這裡類用的是person類 屬性有 id name address 來做例子 public class person public void setid integer id public string getnam...

C 反射 迴圈屬性 字段賦值

private static void copyvaluetotarget t source,t target where t class var properties type.getruntimeproperties tolist foreach var property in properti...

C 各種反射動態賦值取值方法

using system using system.collections.generic using system.linq using system.web using system.web.ui using system.web.ui.webcontrols using system.data...