Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Children and GetChildren in Sitecore? (v8.1)

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)
like image 397
Adam Hess Avatar asked May 11 '16 15:05

Adam Hess


2 Answers

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);
  }
}
like image 69
Vlad Iobagiu Avatar answered Sep 21 '22 02:09

Vlad Iobagiu


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.

like image 34
Marek Musielak Avatar answered Sep 21 '22 02:09

Marek Musielak