Umbraco uSiteBuilder 3.0加载DocumentType字段,但不加载DynamicNode字段
我在使用Umbraco 6.1.5和uSiteBuilder 3.0.0时遇到了一个问题,当我使用Umbraco uSiteBuilder 3.0加载DocumentType字段,但不加载DynamicNode字段,umbraco,umbraco6,Umbraco,Umbraco6,我在使用Umbraco 6.1.5和uSiteBuilder 3.0.0时遇到了一个问题,当我使用ContentHelper实例化强类型的DocumentType时,DocumentType中定义的所有字段都会加载到对象中,但像Name、Id或Children这样的字段不会加载(它们为null、空或0) 据我所知,这是因为负责实例化的ContentHelper方法正在调用dynamicode的空构造函数。我缺少什么吗?我应该在文档类型上定义构造函数吗 以下是我的文档类型: namespace U
ContentHelper
实例化强类型的DocumentType时,DocumentType中定义的所有字段都会加载到对象中,但像Name
、Id
或Children
这样的字段不会加载(它们为null、空或0)
据我所知,这是因为负责实例化的ContentHelper
方法正在调用dynamicode
的空构造函数。我缺少什么吗?我应该在文档类型上定义构造函数吗
以下是我的文档类型:
namespace USiteBuilderTest.DocumentTypes
{
[DocumentType]
public class Home : DocumentTypeBase
{
[DocumentTypeProperty(Name = "Field 1")]
public string Field1 { set; get; }
[DocumentTypeProperty(Name = "Field 2")]
public string Field2 { set; get; }
[DocumentTypeProperty(Name = "Field 3")]
public string Field3 { set; get; }
}
}
如果有帮助,下面是调用空构造函数的代码部分:
Type typeDocType = DocumentTypeManager.GetDocumentTypeType(node.NodeTypeAlias);
if (typeDocType != null)
{
ConstructorInfo constructorInfo = typeDocType.GetConstructor(new[] { typeof(int) });
if (constructorInfo == null)
{
retVal = (DocumentTypeBase)Activator.CreateInstance(typeDocType);
}
else
{
retVal = (DocumentTypeBase)constructorInfo.Invoke(new object[] { node.Id });
}
看起来,尽管Codeplex项目描述明确指出分支“3.0.0”应该与Umbraco v6一起使用,但实际上应该使用一个特定的v6分支(标记为“version6API”) 答案要归功于符拉丹·奥斯托吉奇,他在翁布拉科论坛上回答了这个问题:
我也遇到了这个问题。解决方法是添加一个空构造函数和一个以nodeid作为输入的构造函数。如下所示:
namespace USiteBuilderTest.DocumentTypes
{
[DocumentType]
public class Home : DocumentTypeBase
{
public Home() {}
public Home(int nodeId) : base(nodeId) { }
[DocumentTypeProperty(Name = "Field 1")]
public string Field1 { set; get; }
[DocumentTypeProperty(Name = "Field 2")]
public string Field2 { set; get; }
[DocumentTypeProperty(Name = "Field 3")]
public string Field3 { set; get; }
}
}
这对我来说是个骗局