|
1 |
| -///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1 | +///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
2 | 2 | // Tencent is pleased to support the open source community by making behaviac available.
|
3 | 3 | //
|
4 | 4 | // Copyright (C) 2015-2017 THL A29 Limited, a Tencent company. All rights reserved.
|
@@ -1818,37 +1818,41 @@ public static EOperatorType ParseOperatorType(string operatorType)
|
1818 | 1818 |
|
1819 | 1819 | public static bool Compare<T>(T left, T right, EOperatorType comparisonType)
|
1820 | 1820 | {
|
1821 |
| - bool bLeftNull = (left == null); |
1822 |
| - bool bRightNull = (right == null); |
1823 |
| - |
1824 |
| - if (bLeftNull && bRightNull) // both are null |
1825 |
| - { |
1826 |
| - if (comparisonType == EOperatorType.E_EQUAL) |
1827 |
| - { |
1828 |
| - return true; |
1829 |
| - } |
1830 |
| - else if (comparisonType == EOperatorType.E_NOTEQUAL) |
1831 |
| - { |
1832 |
| - return false; |
1833 |
| - } |
1834 |
| - else |
1835 |
| - { |
1836 |
| - Debug.Check(false); |
1837 |
| - } |
1838 |
| - } |
1839 |
| - else if (bLeftNull || bRightNull) // one is null and ther other one is not null |
| 1821 | + Type type = typeof(T); |
| 1822 | + if (!type.IsValueType) |
1840 | 1823 | {
|
1841 |
| - if (comparisonType == EOperatorType.E_EQUAL) |
1842 |
| - { |
1843 |
| - return false; |
1844 |
| - } |
1845 |
| - else if (comparisonType == EOperatorType.E_NOTEQUAL) |
| 1824 | + bool bLeftNull = (left == null); |
| 1825 | + bool bRightNull = (right == null); |
| 1826 | + |
| 1827 | + if (bLeftNull && bRightNull) // both are null |
1846 | 1828 | {
|
1847 |
| - return true; |
| 1829 | + if (comparisonType == EOperatorType.E_EQUAL) |
| 1830 | + { |
| 1831 | + return true; |
| 1832 | + } |
| 1833 | + else if (comparisonType == EOperatorType.E_NOTEQUAL) |
| 1834 | + { |
| 1835 | + return false; |
| 1836 | + } |
| 1837 | + else |
| 1838 | + { |
| 1839 | + Debug.Check(false); |
| 1840 | + } |
1848 | 1841 | }
|
1849 |
| - else |
| 1842 | + else if (bLeftNull || bRightNull) // one is null and the other is not null |
1850 | 1843 | {
|
1851 |
| - Debug.Check(false); |
| 1844 | + if (comparisonType == EOperatorType.E_EQUAL) |
| 1845 | + { |
| 1846 | + return false; |
| 1847 | + } |
| 1848 | + else if (comparisonType == EOperatorType.E_NOTEQUAL) |
| 1849 | + { |
| 1850 | + return true; |
| 1851 | + } |
| 1852 | + else |
| 1853 | + { |
| 1854 | + Debug.Check(false); |
| 1855 | + } |
1852 | 1856 | }
|
1853 | 1857 | }
|
1854 | 1858 |
|
@@ -1878,15 +1882,9 @@ public static bool Compare<T>(T left, T right, EOperatorType comparisonType)
|
1878 | 1882 | }
|
1879 | 1883 | }
|
1880 | 1884 |
|
1881 |
| - Type type = typeof(T); |
1882 |
| - |
1883 | 1885 | if (!type.IsValueType)
|
1884 | 1886 | {
|
1885 |
| - // reference type |
1886 |
| - object l = (object)left; |
1887 |
| - object r = (object)right; |
1888 |
| - |
1889 |
| - bool bEqual = Object.ReferenceEquals(l, r); |
| 1887 | + bool bEqual = Object.ReferenceEquals(left, right); |
1890 | 1888 |
|
1891 | 1889 | if (bEqual)
|
1892 | 1890 | {
|
|
0 commit comments