我有List<dynamic>
,我需要將列表的值和類型傳遞給服務。 服務代碼將是這樣的:如何獲取C#中動態對象的類型?
Type type = typeof(IList<>);
// Type genericType = how to get type of list. Such as List<**string**>, List<**dynamic**>, List<**CustomClass**>
// Then I convert data value of list to specified type.
IList data = (IList)JsonConvert.DeserializeObject(this._dataSourceValues[i], genericType);
_dataSourceValues:在列表中
我怎樣才能投列表的類型特定類型,如果列表的類型是動態值(List<dynamic>
) ?
[這是否回答幫助?(http://stackoverflow.com/a/557349/61470) – DaveParsons
如果你不知道在編譯的時候你不能類型。(除非你使用反射) –
即使使用反射,也不能將其轉換爲靜態類型的對象。 –