本文整理汇总了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));
}
}
示例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()));
}
示例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());
}
示例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"));
}
示例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)));
}
}
示例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;
}
示例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;
}
示例8: Equals
public void Equals(CultureInfo culture, object value, bool expected)
{
Assert.Equal(expected, culture.Equals(value));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}