本文整理汇总了C#中StringComparer.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# StringComparer.Compare方法的具体用法?C# StringComparer.Compare怎么用?C# StringComparer.Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringComparer
的用法示例。
在下文中一共展示了StringComparer.Compare方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindNodes
/// <summary>
/// Gets all the node indices with matching names.
/// </summary>
private IEnumerable<int> FindNodes(string name, StringComparer comparer)
{
// find any node that matches
var position = BinarySearch(name, comparer);
if (position != -1)
{
// back up to the first node that matches.
var start = position;
while (start > 0 && comparer.Compare(nodes[start - 1].Name, name) == 0)
{
start--;
}
// yield the nodes we already know that match
for (int i = start; i <= position; i++)
{
yield return i;
}
// also yield any following nodes that might also match
for (int i = position + 1; i < nodes.Count; i++)
{
var node = nodes[i];
if (comparer.Compare(node.Name, name) == 0)
{
yield return i;
}
else
{
break;
}
}
}
}
示例2: GetParam
public static string GetParam(this Application application, string name, StringComparer stringComparer)
{
stringComparer = stringComparer ?? StringComparer.CurrentCulture;
return (from child in HtmlPage.Plugin.Children
let nameAttribute = child.GetProperty("name") as string
let valueAttribute = child.GetProperty("value") as string
where stringComparer.Compare(name, nameAttribute) == 0
select valueAttribute as string).FirstOrDefault();
}
示例3: TypeDeobfuscator
internal TypeDeobfuscator(XElement typeNode)
{
m_comparer = StringComparer.Ordinal;
ObfuscatedName = ((string)typeNode.Element("newname")).Replace('/', '+');
OriginalName = ((string)typeNode.Element("name")).Replace('/', '+');
m_fields = (from fieldNode in typeNode.Elements("fieldlist").Elements("field")
let originalName = (string)fieldNode.Element("name")
let obfuscatedName = (string)fieldNode.Element("newname")
select new ObfuscatedField(obfuscatedName, originalName)).ToArray();
Array.Sort(m_fields, (left, right) => m_comparer.Compare(left.ObfuscatedName, right.ObfuscatedName));
}
示例4: VerifyComparer
private static void VerifyComparer(StringComparer sc, bool ignoreCase)
{
String s1 = "Hello";
String s1a = "Hello";
String s1b = "HELLO";
String s2 = "There";
Assert.True(sc.Equals(s1, s1a));
Assert.True(sc.Equals(s1, s1a));
Assert.Equal(0, sc.Compare(s1, s1a));
Assert.Equal(0, ((IComparer)sc).Compare(s1, s1a));
Assert.True(sc.Equals(s1, s1));
Assert.True(((IEqualityComparer)sc).Equals(s1, s1));
Assert.Equal(0, sc.Compare(s1, s1));
Assert.Equal(0, ((IComparer)sc).Compare(s1, s1));
Assert.False(sc.Equals(s1, s2));
Assert.False(((IEqualityComparer)sc).Equals(s1, s2));
Assert.True(sc.Compare(s1, s2) < 0);
Assert.True(((IComparer)sc).Compare(s1, s2) < 0);
Assert.Equal(ignoreCase, sc.Equals(s1, s1b));
Assert.Equal(ignoreCase, ((IEqualityComparer)sc).Equals(s1, s1b));
int result = sc.Compare(s1, s1b);
if (ignoreCase)
Assert.Equal(0, result);
else
Assert.NotEqual(0, result);
result = ((IComparer)sc).Compare(s1, s1b);
if (ignoreCase)
Assert.Equal(0, result);
else
Assert.NotEqual(0, result);
}
示例5: FindItemByPath
public static ProjectItem FindItemByPath(this ProjectItems items, string itemFilePath, StringComparer comparer)
{
foreach (var item in items)
{
var projectItem = item as ProjectItem;
if (projectItem != null)
{
if (projectItem.TryGetFullPath(out var filePath) && comparer.Compare(filePath, itemFilePath) == 0)
{
return projectItem;
}
}
}
return null;
}
示例6: FindItem
public static ProjectItem FindItem(this ProjectItems items, string itemName, StringComparer comparer)
{
return items.OfType<ProjectItem>().FirstOrDefault(p => comparer.Compare(p.Name, itemName) == 0);
}
示例7: VerificationHelper
private bool VerificationHelper(StringComparer sc, string x, string y, int expected, string errorno)
{
bool retVal = true;
int actual = sc.Compare(x, y);
if (actual != expected)
{
TestLibrary.TestFramework.LogError(errorno, "Compare returns wrong value");
TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE]");
retVal = false;
}
else if (actual < expected)
{
}
return retVal;
}
示例8: GetInfoForImmediateNamespaceMembers
/// <summary>
/// Calculates information about types and namespaces immediately contained within a namespace.
/// </summary>
/// <param name="isGlobalNamespace">
/// Is current namespace a global namespace?
/// </param>
/// <param name="namespaceNameLength">
/// Length of the fully-qualified name of this namespace.
/// </param>
/// <param name="typesByNS">
/// The sequence of groups of TypeDef row ids for types contained within the namespace,
/// recursively including those from nested namespaces. The row ids must be grouped by the
/// fully-qualified namespace name in case-sensitive manner.
/// Key of each IGrouping is a fully-qualified namespace name, which starts with the name of
/// this namespace. There could be multiple groups for each fully-qualified namespace name.
///
/// The groups must be sorted by the keys in a manner consistent with comparer passed in as
/// nameComparer. Therefore, all types immediately contained within THIS namespace, if any,
/// must be in several IGrouping at the very beginning of the sequence.
/// </param>
/// <param name="nameComparer">
/// Equality comparer to compare namespace names.
/// </param>
/// <param name="types">
/// Output parameter, never null:
/// A sequence of groups of TypeDef row ids for types immediately contained within this namespace.
/// </param>
/// <param name="namespaces">
/// Output parameter, never null:
/// A sequence with information about namespaces immediately contained within this namespace.
/// For each pair:
/// Key - contains simple name of a child namespace.
/// Value – contains a sequence similar to the one passed to this function, but
/// calculated for the child namespace.
/// </param>
/// <remarks></remarks>
public static void GetInfoForImmediateNamespaceMembers(
bool isGlobalNamespace,
int namespaceNameLength,
IEnumerable<IGrouping<string, TypeDefinitionHandle>> typesByNS,
StringComparer nameComparer,
out IEnumerable<IGrouping<string, TypeDefinitionHandle>> types,
out IEnumerable<KeyValuePair<string, IEnumerable<IGrouping<string, TypeDefinitionHandle>>>> namespaces)
{
Debug.Assert(typesByNS != null);
Debug.Assert(namespaceNameLength >= 0);
Debug.Assert(!isGlobalNamespace || namespaceNameLength == 0);
// A list of groups of TypeDef row ids for types immediately contained within this namespace.
var nestedTypes = new List<IGrouping<string, TypeDefinitionHandle>>();
// A list accumulating information about namespaces immediately contained within this namespace.
// For each pair:
// Key - contains simple name of a child namespace.
// Value – contains a sequence similar to the one passed to this function, but
// calculated for the child namespace.
var nestedNamespaces = new List<KeyValuePair<string, IEnumerable<IGrouping<string, TypeDefinitionHandle>>>>();
bool possiblyHavePairsWithDuplicateKey = false;
var enumerator = typesByNS.GetEnumerator();
using (enumerator)
{
if (enumerator.MoveNext())
{
var pair = enumerator.Current;
// Simple name of the last encountered child namespace.
string lastChildNamespaceName = null;
// A list accumulating information about types within the last encountered child namespace.
// The list is similar to the sequence passed to this function.
List<IGrouping<string, TypeDefinitionHandle>> typesInLastChildNamespace = null;
// if there are any types in this namespace,
// they will be in the first several groups if their key length
// is equal to namespaceNameLength.
while (pair.Key.Length == namespaceNameLength)
{
nestedTypes.Add(pair);
if (!enumerator.MoveNext())
{
goto DoneWithSequence;
}
pair = enumerator.Current;
}
// Account for the dot following THIS namespace name.
if (!isGlobalNamespace)
{
namespaceNameLength++;
}
do
{
pair = enumerator.Current;
string childNamespaceName = ExtractSimpleNameOfChildNamespace(namespaceNameLength, pair.Key);
//.........这里部分代码省略.........
示例9: BinarySearch
// search for a node with matching name in ordered list
private int BinarySearch(string name, StringComparer nameComparer)
{
int max = nodes.Count - 1;
int min = 0;
while (max >= min)
{
int mid = min + ((max - min) >> 1);
var comparison = nameComparer.Compare(nodes[mid].Name, name);
if (comparison < 0)
{
min = mid + 1;
}
else if (comparison > 0)
{
max = mid - 1;
}
else
{
return mid;
}
}
return -1;
}
示例10: ByNodeName
public static Predicate<INode> ByNodeName(string name, StringComparer comparer)
{
return ByNodeName(delegate(string value) { return comparer.Compare(value, name) == 0; });
}
示例11: Contains
public static bool Contains(this string[] strings, string value, StringComparer comparer)
{
return strings.Any(val => comparer.Compare(val, value) == 0);
}