本文整理汇总了C#中StringComparer.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# StringComparer.Equals方法的具体用法?C# StringComparer.Equals怎么用?C# StringComparer.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringComparer
的用法示例。
在下文中一共展示了StringComparer.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Choose
public static ParserResult<object> Choose(
Func<IEnumerable<string>, IEnumerable<OptionSpecification>, StatePair<IEnumerable<Token>>> tokenizer,
IEnumerable<Type> types,
IEnumerable<string> arguments,
StringComparer nameComparer,
CultureInfo parsingCulture)
{
if (arguments.Empty())
{
return MakeNotParsed(types, new NoVerbSelectedError());
}
var firstArg = arguments.First();
Func<string, bool> preprocCompare = command =>
nameComparer.Equals(command, firstArg) ||
nameComparer.Equals(string.Concat("--", command), firstArg);
var verbs = Verb.SelectFromTypes(types);
if (preprocCompare("help"))
{
return MakeNotParsed(types,
MakeHelpVerbRequestedError(verbs,
arguments.Skip(1).SingleOrDefault() ?? string.Empty, nameComparer));
}
if (preprocCompare("version"))
{
return MakeNotParsed(types, new VersionRequestedError());
}
return MatchVerb(tokenizer, verbs, arguments, nameComparer, parsingCulture);
}
示例2: Choose
public static ParserResult<object> Choose(
Func<IEnumerable<string>, IEnumerable<OptionSpecification>, Result<IEnumerable<Token>, Error>> tokenizer,
IEnumerable<Type> types,
IEnumerable<string> arguments,
StringComparer nameComparer,
CultureInfo parsingCulture,
IEnumerable<ErrorType> nonFatalErrors)
{
Func<ParserResult<object>> choose = () =>
{
var firstArg = arguments.First();
Func<string, bool> preprocCompare = command =>
nameComparer.Equals(command, firstArg) ||
nameComparer.Equals(string.Concat("--", command), firstArg);
var verbs = Verb.SelectFromTypes(types);
return preprocCompare("help")
? MakeNotParsed(types,
MakeHelpVerbRequestedError(verbs,
arguments.Skip(1).SingleOrDefault() ?? string.Empty, nameComparer))
: preprocCompare("version")
? MakeNotParsed(types, new VersionRequestedError())
: MatchVerb(tokenizer, verbs, arguments, nameComparer, parsingCulture, nonFatalErrors);
};
return arguments.Any()
? choose()
: MakeNotParsed(types, new NoVerbSelectedError());
}
示例3: MatchName
public static bool MatchName(this string value, string shortName, string longName, StringComparer comparer)
{
if (value == null) throw new ArgumentNullException("value");
return value.Length == 1
? comparer.Equals(value, shortName)
: comparer.Equals(value, longName);
}
示例4: GetClass
public ITypeDefinition GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer)
{
foreach (ITypeDefinition type in types) {
if (nameComparer.Equals(type.Name, name) && nameComparer.Equals(type.Namespace, nameSpace) && type.TypeParameterCount == typeParameterCount)
return type;
}
return null;
}
示例5: FindNodes
/// <summary>
/// Gets all the node indices with matching names per the <paramref name="comparer" />.
/// </summary>
private IEnumerable<int> FindNodes(string name, StringComparer comparer)
{
// find any node that matches case-insensitively
var startingPosition = BinarySearch(name);
if (startingPosition != -1)
{
// yield if this matches by the actual given comparer
if (comparer.Equals(name, _nodes[startingPosition].Name))
{
yield return startingPosition;
}
int position = startingPosition;
while (position > 0 && s_nodeSortComparer.Equals(_nodes[position - 1].Name, name))
{
position--;
if (comparer.Equals(_nodes[position].Name, name))
{
yield return position;
}
}
position = startingPosition;
while (position + 1 < _nodes.Count && s_nodeSortComparer.Equals(_nodes[position + 1].Name, name))
{
position++;
if (comparer.Equals(_nodes[position].Name, name))
{
yield return position;
}
}
}
}
示例6: VersionCommand
public static Func<IEnumerable<string>, IEnumerable<Error>> VersionCommand(StringComparer nameComparer)
{
return
arguments =>
nameComparer.Equals("--version", arguments.First())
? new Error[] { new VersionRequestedError() }
: Enumerable.Empty<Error>();
}
示例7: MatchVerb
private static ParserResult<object> MatchVerb(
Func<IEnumerable<string>, IEnumerable<OptionSpecification>, StatePair<IEnumerable<Token>>> tokenizer,
IEnumerable<Tuple<Verb, Type>> verbs,
IEnumerable<string> arguments,
StringComparer nameComparer,
CultureInfo parsingCulture)
{
return verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
? InstanceBuilder.Build(
Maybe.Just<Func<object>>(() => verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2.AutoDefault()),
tokenizer,
arguments.Skip(1),
nameComparer,
parsingCulture)
: new NotParsed<object>(
new NullInstance(),
verbs.Select(v => v.Item2),
new[] { new BadVerbSelectedError(arguments.First()) });
}
示例8: IndexOf
public static int IndexOf(/*this*/ string[]/*!*/ array, string/*!*/ value, StringComparer/*!*/ comparer) {
ContractUtils.RequiresNotNull(array, "array");
ContractUtils.RequiresNotNull(value, "value");
ContractUtils.RequiresNotNull(comparer, "comparer");
for (int i = 0; i < array.Length; i++) {
if (comparer.Equals(array[i], value)) {
return i;
}
}
return -1;
}
示例9: MakeHelpVerbRequestedError
private static HelpVerbRequestedError MakeHelpVerbRequestedError(
IEnumerable<Tuple<Verb, Type>> verbs,
string verb,
StringComparer nameComparer)
{
return verb.Length > 0
? verbs.SingleOrDefault(v => nameComparer.Equals(v.Item1.Name, verb))
.ToMaybe()
.Return(
v => new HelpVerbRequestedError(v.Item1.Name, v.Item2, true),
new HelpVerbRequestedError(null, null, false))
: new HelpVerbRequestedError(null, null, false);
}
示例10: 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);
}
示例11: FindFreeName
static string FindFreeName(string baseName, List<DeclarationStatement> list1, List<DeclarationStatement> list2, StringComparer nameComparer)
{
string tmp = baseName + "__";
for (int i = 2;; i++) {
string tryName = tmp + i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
bool found = false;
foreach (DeclarationStatement d in list1) {
if (nameComparer.Equals(d.Declaration.Name, tryName)) {
found = true;
break;
}
}
if (found) continue;
foreach (DeclarationStatement d in list2) {
if (nameComparer.Equals(d.Declaration.Name, tryName)) {
found = true;
break;
}
}
if (!found)
return tryName;
}
}
示例12: GetStringDifferHint
public static string GetStringDifferHint(string left, string right, StringComparer comparer)
{
if (left == null) return ", left is null";
if (right == null) return ", right is null";
for (int i = 1; i <= left.Length && i <= right.Length; ++i)
{
//TODO: this doesn't know about surrogate pairs or things like esszett
if (!comparer.Equals(left.Substring(0, i), right.Substring(0, i)))
{
var result = CheckCharactersAt(left, right, i - 1, comparer);
if (result != null) return result;
return string.Format(", strings differ at index {0}, '{1}' != '{2}'", i - 1,
left[i - 1], right[i - 1]);
}
}
return null; //err: they don't differ!
}
示例13: MatchVerb
private static ParserResult<object> MatchVerb(
Func<IEnumerable<string>, IEnumerable<OptionSpecification>, Result<IEnumerable<Token>, Error>> tokenizer,
IEnumerable<Tuple<Verb, Type>> verbs,
IEnumerable<string> arguments,
StringComparer nameComparer,
CultureInfo parsingCulture,
IEnumerable<ErrorType> nonFatalErrors)
{
return verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
? InstanceBuilder.Build(
Maybe.Just<Func<object>>(
() =>
verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2.AutoDefault()),
tokenizer,
arguments.Skip(1),
nameComparer,
false,
parsingCulture,
nonFatalErrors)
: MakeNotParsed(verbs.Select(v => v.Item2), new BadVerbSelectedError(arguments.First()));
}
示例14: Choose
public static ParserResult<object> Choose(
Func<IEnumerable<string>, IEnumerable<OptionSpecification>, StatePair<IEnumerable<Token>>> tokenizer,
IEnumerable<Type> types,
IEnumerable<string> arguments,
StringComparer nameComparer,
CultureInfo parsingCulture)
{
var verbs = Verb.SelectFromTypes(types);
return arguments.Empty()
? ParserResult.Create<object>(
ParserResultType.Verbs, new NullInstance(), new[] { new NoVerbSelectedError() }, Maybe.Just(types))
: nameComparer.Equals("help", arguments.First())
? ParserResult.Create<object>(
ParserResultType.Verbs,
new NullInstance(), new[] { CreateHelpVerbRequestedError(
verbs,
arguments.Skip(1).SingleOrDefault() ?? string.Empty,
nameComparer) }, Maybe.Just(types))
: MatchVerb(tokenizer, verbs, arguments, nameComparer, parsingCulture);
}
示例15: RenameLocals
public static void RenameLocals(Block block, StringComparer nameComparer)
{
FindVariableDeclarationsVisitor fvdv = new FindVariableDeclarationsVisitor();
block.Accept(fvdv);
List<DeclarationStatement> list = new List<DeclarationStatement>();
foreach (DeclarationStatement decl in fvdv.Declarations) {
DeclarationStatement conflict = null;
int conflictIndex = -1;
for (int i = 0; i < list.Count; i++) {
if (nameComparer.Equals(list[i].Declaration.Name, decl.Declaration.Name)) {
conflict = list[i];
conflictIndex = i;
break;
}
}
if (conflict == null) {
list.Add(decl);
} else {
// Handle conflict: try if "moveup" would be sufficient
if (IsSameType(decl.Declaration.Type, conflict.Declaration.Type, nameComparer)) {
// create declaration at beginning of class and
// replace decl & conflict by assignment
DeclarationStatement newDecl = new DeclarationStatement(conflict.LexicalInfo);
newDecl.Declaration = new Declaration(conflict.Declaration.LexicalInfo, conflict.Declaration.Name, conflict.Declaration.Type);
block.Insert(0, newDecl);
ReplaceWithInitializer(decl);
ReplaceWithInitializer(conflict);
list[conflictIndex] = newDecl;
} else {
string newName = FindFreeName(decl.Declaration.Name, list, fvdv.Declarations, nameComparer);
decl.ParentNode.Accept(new RenameLocalsVisitor(decl.Declaration.Name, newName, nameComparer));
decl.Declaration.Name = newName;
}
}
}
}