資源簡介
通過Reflection創建實例
代碼片段和文件信息
using?System;
using?System.Reflection;
public?class?Foo
{
????public?string?Bar?{?get;?set;?}
}
public?class?Program
{
????static?void?Main()
????{
????????string?name?=?“Foo“;
????????string?property?=?“Bar“;
????????string?value?=?“Baz“;
????????//?Get?the?type?contained?in?the?name?string
????????Type?type?=?Type.GetType(name?true);
????????//?create?an?instance?of?that?type
????????object?instan
評論
共有 條評論