Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何用受保护的构造函数和私有属性设置填充对象?_C#_Design Patterns - Fatal编程技术网

C# 如何用受保护的构造函数和私有属性设置填充对象?

C# 如何用受保护的构造函数和私有属性设置填充对象?,c#,design-patterns,C#,Design Patterns,我有一个域对象,如下所示: public class Document { public string Index { get; private set; } public string Title { get; private set; } public string Content { get; private set; } public Document (string index, string title, string content) {

我有一个域对象,如下所示:

public class Document 
{
   public string Index { get; private set; }
   public string Title { get; private set; }
   public string Content { get; private set; }

   public Document (string index, string title, string content)
   {
       // some domain rule here
       Index = index;
       Title = title; 
       Content = content; 
   }
 
   protected Document() {}
}
现在,我想构造
Document
类型的对象,并在我从存储器中提取数据时填充它们的属性,而不需要像Dapper这样的ORM


我想知道Dapper或JSONvert如何使用受保护的构造函数和私有属性设置器来填充对象?

填充字段的构造函数不受保护,它是公共的

有些包足够聪明,或者带有属性,因此您可以教它们使用这些构造函数,而有些包只使用反射。可以使用反射写入私有属性