[英]C# Array of anonymous class inside another anonymous class
我反序列化一個JSon字符串,該字符串包含一個帶有子對象數組的對象。
當前有效的解決方案如下所示:
var definition = new { systems = new subclass[0] };
var ret = JsonConvert.DeserializeAnonymousType(source, definition);
public class subclass
{
public long id;
}
有沒有辦法用另一個匿名類替換子類?
我嘗試使用以下內容,但僅出現編譯器錯誤:
var definition = new { constellations = new{ id=0L }[0] };
我想知道您是否可以:
var definition = new { systems = MakeEmptyArrayFrom(new { id = 0L}) };
...
static T[] MakeEmptyArrayFrom<T>(T value) => new T[0];
注意:如果可行,即使您使用類似的方法也可能可行:
static T[] MakeNullArrayFrom<T>(T value) => null;
正如我想象的那樣,庫對Type
興趣大於對value的興趣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.