1
該類將在runtime
和values
中聲明,對象存儲爲session
或ViewBag
。現在我想創建該類的實例,並使用Bag數據將其屬性設置爲。我知道我應該使用reflection
,但我不知道是否有任何方法開箱即用那樣做的事情或我應該創建一個?如何創建類實例並從Bag對象中設置屬性,如會話
session["Foo"] = "foo";
session["Bar"] = "bar";
var instance = System.Activator.CreateInstance(Type.GetType(className));
instance = ? // how to set properties using session
該類在設計時不可用,應用程序不知道它的屬性是什麼。
class in not available in design time,and application does not know what what its properties are –
This should work –