Added .Except, .Intersect, .Union and .Distinct to DynamicNodeList
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace umbraco.MacroEngines
|
||||
{
|
||||
public class DynamicNodeIdEqualityComparer : EqualityComparer<DynamicNode>
|
||||
{
|
||||
|
||||
public override bool Equals(DynamicNode x, DynamicNode y)
|
||||
{
|
||||
//Check whether the compared objects reference the same data.
|
||||
if (Object.ReferenceEquals(x, y)) return true;
|
||||
|
||||
//Check whether any of the compared objects is null.
|
||||
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
|
||||
return false;
|
||||
|
||||
//Check whether the nodes ids are equal.
|
||||
return x.Id == y.Id;
|
||||
|
||||
}
|
||||
|
||||
public override int GetHashCode(DynamicNode obj)
|
||||
{
|
||||
if (Object.ReferenceEquals(obj, null)) return 0;
|
||||
|
||||
//Get hash code for the Name field if it is not null.
|
||||
int hashId = obj.Id.GetHashCode();
|
||||
|
||||
return hashId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,50 @@ namespace umbraco.MacroEngines
|
||||
result = Aggregate(args, name);
|
||||
return true;
|
||||
}
|
||||
if (name == "Union")
|
||||
{
|
||||
if ((args.First() as IEnumerable<DynamicNode>) != null)
|
||||
{
|
||||
result = new DynamicNodeList(this.Items.Union(args.First() as IEnumerable<DynamicNode>));
|
||||
return true;
|
||||
}
|
||||
if ((args.First() as DynamicNodeList) != null)
|
||||
{
|
||||
result = new DynamicNodeList(this.Items.Union((args.First() as DynamicNodeList).Items));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (name == "Except")
|
||||
{
|
||||
if ((args.First() as IEnumerable<DynamicNode>) != null)
|
||||
{
|
||||
result = new DynamicNodeList(this.Items.Except(args.First() as IEnumerable<DynamicNode>, new DynamicNodeIdEqualityComparer()));
|
||||
return true;
|
||||
}
|
||||
if ((args.First() as DynamicNodeList) != null)
|
||||
{
|
||||
result = new DynamicNodeList(this.Items.Except((args.First() as DynamicNodeList).Items, new DynamicNodeIdEqualityComparer()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (name == "Intersect")
|
||||
{
|
||||
if ((args.First() as IEnumerable<DynamicNode>) != null)
|
||||
{
|
||||
result = new DynamicNodeList(this.Items.Intersect(args.First() as IEnumerable<DynamicNode>, new DynamicNodeIdEqualityComparer()));
|
||||
return true;
|
||||
}
|
||||
if ((args.First() as DynamicNodeList) != null)
|
||||
{
|
||||
result = new DynamicNodeList(this.Items.Intersect((args.First() as DynamicNodeList).Items, new DynamicNodeIdEqualityComparer()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (name == "Distinct")
|
||||
{
|
||||
result = new DynamicNodeList(this.Items.Distinct(new DynamicNodeIdEqualityComparer()));
|
||||
return true;
|
||||
}
|
||||
if (name == "Pluck" || name == "Select")
|
||||
{
|
||||
result = Pluck(args);
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<Compile Include="RazorDynamicNode\DynamicMediaList.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RazorDynamicNode\DynamicNodeIdEqualityComparer.cs" />
|
||||
<Compile Include="RazorDynamicNode\DynamicNodeList.cs" />
|
||||
<Compile Include="RazorDynamicNode\ExamineBackedMedia.cs" />
|
||||
<Compile Include="RazorDynamicNode\Grouping.cs" />
|
||||
|
||||
Reference in New Issue
Block a user