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


C# StringComparer.Equals方法代码示例

本文整理汇总了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);
        }
开发者ID:TeaDrivenDev,项目名称:commandline,代码行数:34,代码来源:InstanceChooser.cs

示例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());
        }
开发者ID:Rusk85,项目名称:commandline,代码行数:31,代码来源:InstanceChooser.cs

示例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);
        }
开发者ID:BiYiTuan,项目名称:commandline,代码行数:8,代码来源:NameExtensions.cs

示例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;
		}
开发者ID:JustasB,项目名称:cudafy,代码行数:8,代码来源:MinimalResolveContext.cs

示例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;
                    }
                }
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:38,代码来源:SymbolTreeInfo.cs

示例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>();
 }
开发者ID:TeaDrivenDev,项目名称:commandline,代码行数:8,代码来源:PreprocessorGuards.cs

示例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()) });
 }
开发者ID:danbowker,项目名称:commandline,代码行数:19,代码来源:InstanceChooser.cs

示例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;
            }
开发者ID:mscottford,项目名称:ironruby,代码行数:13,代码来源:Utils.cs

示例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);
 }
开发者ID:Rusk85,项目名称:commandline,代码行数:13,代码来源:InstanceChooser.cs

示例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);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:38,代码来源:StringComparer.cs

示例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;
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:23,代码来源:RenameLocalsVisitor.cs

示例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!
        }
开发者ID:holmstrom,项目名称:PowerAssert.Net,代码行数:20,代码来源:HintUtils.cs

示例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()));
 }
开发者ID:RyanGrange,项目名称:commandline,代码行数:21,代码来源:InstanceChooser.cs

示例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);
        }
开发者ID:ArsenShnurkov,项目名称:GrammarCompiler,代码行数:21,代码来源:InstanceChooser.cs

示例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;
					}
				}
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:36,代码来源:RenameLocalsVisitor.cs


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