Exemplo n.º 1
0
 private static CompareResult Compare(ScriptingValue a, ScriptingValue b)
 {
     if (a.IsInvokable || b.IsInvokable)
     {
         return(CompareResult.NotComparable);
     }
     else if (a.IsArray && b.IsArray)
     {
         return(a.SequenceEqual(b, new ScriptingValueComparer()) ? CompareResult.EqualTo : CompareResult.NotComparable);
     }
     else
     {
         try
         {
             object obja = a.Value;
             object objb = b.Value;
             if (obja is int)
             {
                 if (objb is int)
                 {
                     return(ConvertCompareResult(((int)obja).CompareTo((int)objb)));
                 }
                 else if (objb is double)
                 {
                     return(ConvertCompareResult(((double)(int)obja).CompareTo((double)objb)));
                 }
             }
             else if (obja is double)
             {
                 if (objb is int)
                 {
                     return(ConvertCompareResult(((double)obja).CompareTo((double)(int)objb)));
                 }
                 else if (objb is double)
                 {
                     return(ConvertCompareResult(((double)obja).CompareTo((double)objb)));
                 }
             }
             else if (obja is string)
             {
                 if (objb is string)
                 {
                     return(ConvertCompareResult(((string)obja).CompareTo((string)objb)));
                 }
             }
             else if (obja is bool)
             {
                 if (objb is bool)
                 {
                     return(ConvertCompareResult(((bool)obja).CompareTo((bool)objb)));
                 }
             }
             return(ConvertCompareResult(((IComparable)obja).CompareTo(objb)));
         }
         catch (Exception)
         {
             return(CompareResult.NotComparable);
         }
     }
 }