[longomatch] Fix ActionLink equality check



commit 9aab54aa01736b8440b7b45f48bf8dd5b37fd310
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Apr 13 19:05:44 2015 +0200

    Fix ActionLink equality check

 LongoMatch.Core/Common/ExtensionMethods.cs |   33 +++++++++++++++++++--------
 LongoMatch.Core/Store/ActionLink.cs        |    6 +---
 2 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/LongoMatch.Core/Common/ExtensionMethods.cs b/LongoMatch.Core/Common/ExtensionMethods.cs
index d13f56d..888225d 100644
--- a/LongoMatch.Core/Common/ExtensionMethods.cs
+++ b/LongoMatch.Core/Common/ExtensionMethods.cs
@@ -23,29 +23,42 @@ namespace LongoMatch.Core.Common
 {
        public static class ExtensionMethods
        {
-               public static void Swap<T>(this List<T> list, T e1, T e2)
+               public static void Swap<T> (this List<T> list, T e1, T e2)
                {
                        int index1, index2;
                        
                        index1 = list.IndexOf (e1);
                        index2 = list.IndexOf (e2);
-                       T temp = list[index1];
-                       list[index1] = list[index2];
-                       list[index2] = temp;
+                       T temp = list [index1];
+                       list [index1] = list [index2];
+                       list [index2] = temp;
                }
-               
-               public static T[] Merge<T>(this List<T[]> list) {
-                       var res = new List<T>();
+
+               public static T[] Merge<T> (this List<T[]> list)
+               {
+                       var res = new List<T> ();
                        
                        foreach (T[] t in list) {
                                res.AddRange (t);
                        }
                        return res.ToArray ();
                }
-               
-               public static TKey GetKeyByValue<TKey, TValue>(this Dictionary<TKey, TValue> dict, TValue 
value)
+
+               public static TKey GetKeyByValue<TKey, TValue> (this Dictionary<TKey, TValue> dict, TValue 
value)
+               {
+                       return dict.SingleOrDefault (x => x.Value.Equals (value)).Key;
+               }
+
+               public static bool SequenceEqualSafe<T> (this List<T> first, List<T> second)
                {
-                       return dict.SingleOrDefault(x => x.Value.Equals(value)).Key;
+                       if (first == null && second == null) {
+                               return true;
+                       } else if (first == null || second == null) {
+                               return false;
+                       } else {
+                               return first.SequenceEqual (second);
+                       }
+
                }
        }
 }
diff --git a/LongoMatch.Core/Store/ActionLink.cs b/LongoMatch.Core/Store/ActionLink.cs
index 0abdd96..5233401 100644
--- a/LongoMatch.Core/Store/ActionLink.cs
+++ b/LongoMatch.Core/Store/ActionLink.cs
@@ -41,7 +41,6 @@ namespace LongoMatch.Core.Store
                /// <summary>
                /// The source button of the link
                /// </summary>
-               [JsonIgnore]
                public DashboardButton SourceButton {
                        get;
                        set;
@@ -50,7 +49,6 @@ namespace LongoMatch.Core.Store
                /// <summary>
                /// A list of tags that needs to match in the source
                /// </summary>
-               [JsonIgnore]
                public List<Tag> SourceTags {
                        get;
                        set;
@@ -114,8 +112,8 @@ namespace LongoMatch.Core.Store
                            link.DestinationButton != DestinationButton) {
                                return false;
                        }
-                       if (!link.SourceTags.SequenceEqual (SourceTags) ||
-                           !link.DestionationTags.SequenceEqual (DestionationTags)) {
+                       if (!link.SourceTags.SequenceEqualSafe (SourceTags) ||
+                           !link.DestionationTags.SequenceEqualSafe (DestionationTags)) {
                                return false;
                        }
                        return true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]