So looking through the Sitecore code I notice multiple ways to get the children of an Item
.
// Summary:
// Gets the children.
public ChildList GetChildren();
and
// Summary:
// Gets a list of child items.
public ChildList Children { get; }
Any thoughts on the differences between them?
Also do not confuse with the overloaded method:
GetChildren(ChildListOptions options)
Item.GetChildren() allows parameters to alter functionality. This flexibility is why .GetChildren() is preferred over .Children for retrieving a ChildList collection of children items.
For example, to ignore any security applied on those items, use: item.GetChildren(Sitecore.Collections.ChildListOptions.IgnoreSecurity)
Above is the code for these three 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);
}
}
There is no difference between them
They both call ItemManager.GetChildren();
in behind with ChildListOptions.None
options.
And they both return ChildList
object in return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With