小编Art*_*yom的帖子

将 Dictionary<string, object> 转换为类和子类

如何以递归方式将字典转换为类和子类?这些是我的课程:

public class UiItem
{
    public string id { get; set; }
    public string text { get; set; }
    public Rect rect { get; set; } 
}

public class Rect
{
    public int height { get; set; }
    public int width { get; set; }
    public int y { get; set; }
    public int x { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我写了这个,但我不知道如何Rect在类中创建对象UiItem

public static T GetObject<T>(this Dictionary<string, object> dict)
    {
        Type type = typeof(T);
        var obj = …
Run Code Online (Sandbox Code Playgroud)

c# dictionary

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

dictionary ×1