Skip to content

Commit

Permalink
Merge branch 'patch-node-equality' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
NightOwl888 committed Jun 5, 2014
2 parents 5afcf29 + 8be92d8 commit d70ab89
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ public void CopyTo(ISiteMapNode node)
throw new NotImplementedException();
}

public bool Equals(ISiteMapNode node)
{
if (base.Equals(node))
{
return true;
}

return this.Key.Equals(node.Key);
}

#endregion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ protected virtual ISiteMapNode CreateNodesFromMvcSiteMapNodeAttributeDefinitions
foreach (var dynamicNode in dynamicNodesForChildNode)
{
// Verify parent/child relation
if (dynamicNode.ParentNode == parentNode
if (dynamicNode.ParentNode.Equals(parentNode)
&& !siteMap.GetChildNodes(parentNode).Contains(dynamicNode))
{
siteMap.AddNode(dynamicNode, parentNode);
Expand Down Expand Up @@ -325,7 +325,7 @@ protected virtual ISiteMapNode CreateNodesFromMvcSiteMapNodeAttributeDefinitions
foreach (var dynamicNode in dynamicNodesForChildNode)
{
// Verify parent/child relation
if (dynamicNode.ParentNode == parentNode
if (dynamicNode.ParentNode.Equals(parentNode)
&& !siteMap.GetChildNodes(parentNode).Contains(dynamicNode))
{
siteMap.AddNode(dynamicNode, parentNode);
Expand Down
2 changes: 1 addition & 1 deletion src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace MvcSiteMapProvider
/// node in the hierarchy.
/// </summary>
public interface ISiteMapNode
: ISortable
: ISortable, IEquatable<ISiteMapNode>
{
string Key { get; }
bool IsDynamic { get; }
Expand Down
61 changes: 61 additions & 0 deletions src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -775,5 +775,66 @@ public override void CopyTo(ISiteMapNode node)
}

#endregion

#region IEquatable<ISiteMapNode> Members

public override bool Equals(ISiteMapNode node)
{
if (base.Equals((object)node))
{
return true;
}

return this.Key.Equals(node.Key);
}

#endregion

#region System.Object Overrides

public override bool Equals(object obj)
{
ISiteMapNode node = obj as ISiteMapNode;
if (node == null)
{
return false;
}

return this.Equals(node);
}

public static bool operator ==(SiteMapNode node1, SiteMapNode node2)
{
// If both are null, or both are same instance, return true.
if (object.ReferenceEquals(node1, node2))
{
return true;
}

// If one is null, but not both, return false.
if (((object)node1 == null) || ((object)node2 == null))
{
return false;
}

return node1.Equals(node2);
}

public static bool operator !=(SiteMapNode node1, SiteMapNode node2)
{
return !(node1 == node2);
}

public override int GetHashCode()
{
return this.Key.GetHashCode();
}

public override string ToString()
{
return this.Key;
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ protected virtual ISiteMapNodeCollection SiblingNodes
}
}

// TODO: rework... (maartenba)

/// <summary>
/// Determines whether the specified node is in current path.
/// </summary>
Expand All @@ -161,7 +159,7 @@ protected virtual ISiteMapNodeCollection SiblingNodes
public override bool IsInCurrentPath()
{
ISiteMapNode node = this;
return (this.SiteMap.CurrentNode != null && (node == this.SiteMap.CurrentNode || this.SiteMap.CurrentNode.IsDescendantOf(node)));
return (this.SiteMap.CurrentNode != null && (this.SiteMap.CurrentNode.Equals(node) || this.SiteMap.CurrentNode.IsDescendantOf(node)));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public virtual bool IsAccessibleToUser()
public abstract string Controller { get; set; }
public abstract string Action { get; set; }
public abstract void CopyTo(ISiteMapNode node);
public abstract bool Equals(ISiteMapNode node);

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public SiteMapNodeModel(ISiteMapNode node, IDictionary<string, object> sourceMet
Url = node.Url;
CanonicalUrl = node.CanonicalUrl;
MetaRobotsContent = node.GetMetaRobotsContentString();
IsCurrentNode = (node == node.SiteMap.CurrentNode);
IsCurrentNode = (node.Equals(node.SiteMap.CurrentNode));
IsInCurrentPath = node.IsInCurrentPath();
IsRootNode = (node == node.SiteMap.RootNode);
IsRootNode = (node.Equals(node.SiteMap.RootNode));
IsClickable = node.Clickable;
VisibilityAffectsDescendants = visibilityAffectsDescendants;
RouteValues = node.RouteValues;
Expand Down Expand Up @@ -347,7 +347,7 @@ private bool ReachedMaximalNodelevel(int maxDepth, ISiteMapNode node, bool drill
return false;
if (node.IsInCurrentPath())
return true;
if (node.ParentNode == node.SiteMap.CurrentNode)
if (node.ParentNode != null && node.ParentNode.Equals(node.SiteMap.CurrentNode))
return true;
foreach (ISiteMapNode sibling in node.ParentNode.ChildNodes)
{
Expand Down

0 comments on commit d70ab89

Please sign in to comment.