YamlDotNet can not find property

你离开我真会死。 提交于 2019-12-13 16:31:17

问题


I am trying to create a simple model for parsing a yaml file to my domain object using YamlDotNet. The caveat is, that I want the domain model to be readonly, so I'm attempting to solve this through inheritance and internal setters.

For some reason though, the library throws an exception stating:

Property 'HtmlTemplate' not found on type 'ConsoleApplication1.Repositories.YamlTemplateRepository+DeserializeableTemplate'.

I am using an alias, but even scratching that, and using a test class with the right property names does not set it right.

What am I doing wrong? Have I misunderstood how the library should be used?

The code that calls YamlDotNet looks like this:

deserializer.Deserialize<DeserializeableTemplate>(yamlContents);

and the class I'm deserializing looks like this:

private class DeserializeableTemplate : Template
{
  [YamlMember(Alias = "HtmlTemplate")]
  public string HtmlTemplateWrapper
  {
    get { return HtmlTemplate; }
    set { HtmlTemplate = value; }
  }

  // A few more properties...
}

and the class I am inheriting:

public class Template
{
  public string HtmlTemplate { get; internal set; }
  // A few more properties...
}

(Small console test application with the same error can be found here)

来源:https://stackoverflow.com/questions/41300528/yamldotnet-can-not-find-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!