Sitecore 中的 Children 和 GetChildren 有什么区别? (v8.1)
What's the difference between Children and GetChildren in Sitecore? (v8.1)
因此,通过查看 Sitecore 代码,我注意到有多种获取 Item
子项的方法。
// Summary:
// Gets the children.
public ChildList GetChildren();
和
// Summary:
// Gets a list of child items.
public ChildList Children { get; }
对它们之间的区别有什么想法吗?
也不要与重载方法混淆:
GetChildren(ChildListOptions options)
两者没有区别
他们都在后面调用 ItemManager.GetChildren();
ChildListOptions.None
个选项。
他们都 return ChildList
反对 return。
Item.GetChildren() 允许参数改变功能。这种灵活性就是为什么 .GetChildren() 优于 .Children 来检索子项的 ChildList 集合的原因。
例如,要忽略应用于这些项目的任何安全性,请使用:item.GetChildren(Sitecore.Collections.ChildListOptions.IgnoreSecurity)
以上是这三个的代码methods/property
public ChildList GetChildren()
{
return this.GetChildren(ChildListOptions.None);
}
public ChildList GetChildren(ChildListOptions options)
{
return Sitecore.Diagnostics.Assert.ResultNotNull<ChildList>(ItemManager.GetChildren(this, (options & ChildListOptions.IgnoreSecurity) != ChildListOptions.None ? SecurityCheck.Disable : SecurityCheck.Enable, options));
}
public ChildList Children
{
get
{
return new ChildList(this);
}
}
因此,通过查看 Sitecore 代码,我注意到有多种获取 Item
子项的方法。
// Summary:
// Gets the children.
public ChildList GetChildren();
和
// Summary:
// Gets a list of child items.
public ChildList Children { get; }
对它们之间的区别有什么想法吗?
也不要与重载方法混淆:
GetChildren(ChildListOptions options)
两者没有区别
他们都在后面调用 ItemManager.GetChildren();
ChildListOptions.None
个选项。
他们都 return ChildList
反对 return。
Item.GetChildren() 允许参数改变功能。这种灵活性就是为什么 .GetChildren() 优于 .Children 来检索子项的 ChildList 集合的原因。
例如,要忽略应用于这些项目的任何安全性,请使用:item.GetChildren(Sitecore.Collections.ChildListOptions.IgnoreSecurity)
以上是这三个的代码methods/property
public ChildList GetChildren()
{
return this.GetChildren(ChildListOptions.None);
}
public ChildList GetChildren(ChildListOptions options)
{
return Sitecore.Diagnostics.Assert.ResultNotNull<ChildList>(ItemManager.GetChildren(this, (options & ChildListOptions.IgnoreSecurity) != ChildListOptions.None ? SecurityCheck.Disable : SecurityCheck.Enable, options));
}
public ChildList Children
{
get
{
return new ChildList(this);
}
}