当前位置: 首页>>代码示例>>C#>>正文


C# CultureInfo.Equals方法代码示例

本文整理汇总了C#中CultureInfo.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# CultureInfo.Equals方法的具体用法?C# CultureInfo.Equals怎么用?C# CultureInfo.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CultureInfo的用法示例。


在下文中一共展示了CultureInfo.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompareVarying

        private static void CompareVarying(string one, string two, int compareValue, string culture, CompareOptions compareOptions)
        {
            StringComparer comp = new CultureInfo(culture).CompareInfo.GetStringComparer(compareOptions);

            Assert.Equal(compareValue, comp.Compare(one, two));
            if (compareValue == 0)
            {
                Assert.True(comp.Equals(one, two));
            }
            else
            {
                Assert.False(comp.Equals(one, two));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:GlobalizationExtensionsTests.cs

示例2: Equals

        public void Equals(string cultureName1, CompareOptions options1, string cultureName2, CompareOptions options2, bool expected)
        {
            StringComparer comparer1 = new CultureInfo(cultureName1).CompareInfo.GetStringComparer(options1);
            StringComparer comparer2 = new CultureInfo(cultureName2).CompareInfo.GetStringComparer(options2);

            Assert.Equal(expected, comparer1.Equals(comparer2));
            Assert.Equal(expected, comparer1.GetHashCode().Equals(comparer2.GetHashCode()));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:8,代码来源:GetStringComparerTests.cs

示例3: CompareInfoIdentityTests

        public static void CompareInfoIdentityTests()
        {
            StringComparer us = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
            StringComparer us2 = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
            StringComparer usNoSym = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreSymbols);
            StringComparer fr = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
            StringComparer frOrdinal = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.Ordinal);

            Assert.True(us.Equals(us2));
            Assert.False(us.Equals(usNoSym));
            Assert.False(us.Equals(fr));
            Assert.False(us.Equals(frOrdinal));

            Assert.Equal(us.GetHashCode(), us2.GetHashCode());
            Assert.NotEqual(us.GetHashCode(), usNoSym.GetHashCode());
            Assert.NotEqual(us.GetHashCode(), fr.GetHashCode());
            Assert.NotEqual(frOrdinal.GetHashCode(), fr.GetHashCode());
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:18,代码来源:GlobalizationExtensionsTests.cs

示例4: CompareInfoBasicTests

        public static void CompareInfoBasicTests()
        {
            string one = "A test string";
            string aCopyOfOne = one;

            StringComparer comp = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);

            Assert.Equal(0, comp.Compare(one, aCopyOfOne));
            Assert.True(comp.Equals(one, aCopyOfOne));

            Assert.Equal(-1, comp.Compare(null, one));
            Assert.Equal(0, comp.Compare(null, null));
            Assert.Equal(1, comp.Compare(one, null));

            Assert.False(comp.Equals(null, one));
            Assert.True(comp.Equals(null, null));
            Assert.False(comp.Equals(one, null));

            Assert.Equal(comp.GetHashCode("abc"), comp.GetHashCode("ABC"));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:20,代码来源:GlobalizationExtensionsTests.cs

示例5: Compare

        public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedWindows, int expectedICU)
        {
            int expected = s_isWindows ? expectedWindows : expectedICU;
            StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options);

            Assert.Equal(expected, Math.Sign(comparer.Compare(x, y)));
            Assert.Equal((expected == 0), comparer.Equals(x, y));

            if (x != null && y != null)
            {
                Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y)));
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:GetStringComparerTests.cs

示例6: PosTest1

    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1:CultureTypes.SpecificCultures");
        try
        {
          
            string myLcid = new CultureInfo("en-us").Name;
            if (!myLcid.Equals( new CultureInfo("en-us").TextInfo.CultureName ) )
            {
                TestLibrary.TestFramework.LogError("001", "the licd  of 'zh-CHT' culture should equal to textInfo.LCID.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:24,代码来源:cultureinfotextinfo.cs

示例7: PosTest2

    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Other (CultureTypes.NeutralCultures)  CultureInfo comes from GetCultureInfo method with the same paramter is the same CultureInfo as the original");
        try
        {

            CultureInfo myCultureInfo = new CultureInfo("en-US");
            CultureInfo myCultureInfo1 = new CultureInfo("en-US");
            if (!myCultureInfo1.Equals(myCultureInfo))
            {
                TestLibrary.TestFramework.LogError("003", "Other CultureInfo comes from GetCultureInfo method with the same paramter should be the same CultureInfo as the original.");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:26,代码来源:cultureinfogetcultureinfo2.cs

示例8: Equals

 public void Equals(CultureInfo culture, object value, bool expected)
 {
     Assert.Equal(expected, culture.Equals(value));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:4,代码来源:CultureInfoEquals.cs

示例9: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest2: Verify the TextInfo is not same CultureInfo's . ";
        const string c_TEST_ID = "P002";


       TextInfo textInfoFrance = new CultureInfo("fr-FR").TextInfo;
       TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;

       TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (textInfoFrance.Equals((object)textInfoUS))
            {
                string errorDesc = "the TextInfos of differente CultureInfo should not equal. ";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
           
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:30,代码来源:textinfoequals.cs

示例10: PosTest6

    public bool PosTest6()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest6: Verify the TextInfo not equal a string object . ";
        const string c_TEST_ID = "P006";


        TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;
        String str = TestLibrary.Generator.GetString(-55, false,c_MINI_STRING_LENGTH,c_MAX_STRING_LENGTH);
        object strObject = str as object;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (textInfoUS.Equals(strObject))
            {
                string errorDesc = "the US CultureInfo's TextInfo should not equal string object. ";
                TestLibrary.TestFramework.LogError("009" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("010" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:31,代码来源:textinfoequals.cs

示例11: PosTest5

    public bool PosTest5()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest5: Verify the TextInfo not equal a int object . ";
        const string c_TEST_ID = "P005";


        TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;
        int i = TestLibrary.Generator.GetInt32(-55);
        object intObject = i as object;
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (textInfoUS.Equals(intObject))
            {
                string errorDesc = "the US CultureInfo's TextInfo should not equal int object. ";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:30,代码来源:textinfoequals.cs

示例12: PosTest4

    public bool PosTest4()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest4: Verify the TextInfo not equal another type object . ";
        const string c_TEST_ID = "P004";


        TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;
        object obj = (object)(new MyClass());
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (textInfoUS.Equals(obj))
            {
                string errorDesc = "the US CultureInfo's TextInfo should not equal user-defined type object. ";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:29,代码来源:textinfoequals.cs

示例13: PosTest3

    public bool PosTest3()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest3: Verify the TextInfo not equal a null reference . ";
        const string c_TEST_ID = "P003";


        TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (textInfoUS.Equals(null))
            {
                string errorDesc = "the US CultureInfo's TextInfo should not equal a null reference. ";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:29,代码来源:textinfoequals.cs

示例14: PosTest7

    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest7()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest5: Compare to null");
        try
        {

            CultureInfo myCultureInfo = new CultureInfo("en-US");

            if (myCultureInfo.Equals(null))
            {
                TestLibrary.TestFramework.LogError("013", "Should not be  the same Culture.");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:26,代码来源:cultureinfogetcultureinfo2.cs

示例15: PosTest6

    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest6()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest6: Compare to itself ");
        try
        {

            CultureInfo myCultureInfo = new CultureInfo("en-US");
            if (!myCultureInfo.Equals(myCultureInfo))
            {
                TestLibrary.TestFramework.LogError("011", "Should be the same Culture.");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:25,代码来源:cultureinfogetcultureinfo2.cs


注:本文中的CultureInfo.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。