0

我正在尝试获取这种类型的对象(通过 Web API):

public class Document 
{
    public int Id { get; set; }
    public FileFolder Folder { get; set; }
    public FileFolder FolderParent 
    {
        get
        {
            return FileFolder.Folder;
        }
    }
}

我收到错误消息:

“从 'Domain.Document' 上的 'FolderParent' 获取值时出错。”

4

1 回答 1

2

我把一个简单的小例子放在一起,它可以很好地序列化。似乎该错误必须来自我们现在没有的 FileFolder 类的设计中的某个地方。

[TestClass]
public class UnitTest8
{
    [TestMethod]
    public void TestJasonFileFolder()
    {
        var folder = new FileFolder();
        folder.Folder = new FileFolder { Name = "Parent" };
        folder.Name = "Something";

        var document = new Document { Folder = folder, Id = 1 };

        var test = JsonConvert.SerializeObject(document);
        Assert.IsNotNull(test);
    }
}

public class Document
{
    public int Id { get; set; }
    public FileFolder Folder { get; set; }
    public FileFolder FolderParent
    {
        get
        {
            return this.Folder.Folder;
        }
    }
}

public class FileFolder
{
    public string Name { get; set; }
    public FileFolder Folder { get; set; }
}
于 2013-05-03T15:38:19.477 回答