本文整理汇总了C#中StringComparer类的典型用法代码示例。如果您正苦于以下问题:C# StringComparer类的具体用法?C# StringComparer怎么用?C# StringComparer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringComparer类属于命名空间,在下文中一共展示了StringComparer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EACodeLanguage
/// <summary>
/// Creates a new Event Assembler code language
/// </summary>
/// <param name="name">Name of the language</param>
/// <param name="pointerMaker">Pointer maker for this language</param>
/// <param name="pointerList">Pointer list of this langauge, String is the name of the
/// label to point to, List are the priorities that are pointed to.</param>
/// <param name="pointerListParameters">Array of amount of pointers per POIN code for pointer list.</param>
public EACodeLanguage(string name, IPointerMaker pointerMaker,
Tuple<string, List<Priority>>[][] pointerList,
ICodeTemplateStorer codeStorer, StringComparer stringComparer)
{
this.name = name;
this.codeStorage = codeStorer;
//codeStorage.AddCode(new RawCodeTemplate(stringComparer), Priority.low);
//codeStorage.AddCode(new CodeFillerTemplate(stringComparer), Priority.low);
foreach (ICodeTemplate template in codeStorer)
{
CodeTemplate template2 = template as CodeTemplate;
if (template2 != null)
{
template2.PointerMaker = pointerMaker;
}
}
reservedWords = new List<string> {
offsetChanger, //Offset changing code
alignOffset, //Offset aligning code
currentOffset, //Referances current offset
messagePrinter, //Print message to message box/something
errorPrinter, //Print message to message box/something
warningPrinter //Print message to message box/something
};
this.assembler = new EAExpressionAssembler(codeStorage, null);
this.disassembler = new EACodeLanguageDisassembler(
codeStorage, pointerMaker, pointerList);
}
示例2: CopyOnWriteHashtable
/// <summary>
/// Construct over an IDictionary instance.
/// </summary>
/// <param name="dictionary"></param>
/// <param name="stringComparer">The string comparer to use.</param>
internal CopyOnWriteHashtable(IDictionary dictionary, StringComparer stringComparer)
{
ErrorUtilities.VerifyThrowArgumentNull(dictionary, "dictionary");
ErrorUtilities.VerifyThrowArgumentNull(stringComparer, "stringComparer");
this.sharedLock = new object();
CopyOnWriteHashtable source = dictionary as CopyOnWriteHashtable;
if (source != null)
{
if (source.stringComparer.GetHashCode() == stringComparer.GetHashCode())
{
// If we're copying another CopyOnWriteHashtable then we can defer the clone until later.
ConstructFrom(source);
return;
}
else
{
// Technically, it would be legal to fall through here and let a new hashtable be constructed.
// However, Engine is supposed to use consistent case comparisons everywhere and so, for us,
// this means a bug in the engine code somewhere.
throw new InternalErrorException("Bug: Changing the case-sensitiveness of a copied hash-table.");
}
}
// Can't defer this because we don't control what gets written to the dictionary exogenously.
writeableData = new Hashtable(dictionary, stringComparer);
readonlyData = null;
this.stringComparer = stringComparer;
}
示例3: 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());
}
示例4: NUnitTestAttributeName
/// <summary>
/// Creates a new instance of the NUnit Test Attribute class.
/// </summary>
/// <param name="name">The name of the attribute (e.g. Test) not
/// the full name of the attribute (e.g. TestAttribute).</param>
/// <param name="nameComparer">The string comparer to use
/// when comparing attribute names.</param>
public NUnitTestAttributeName(string name, StringComparer nameComparer)
{
this.name = name;
this.nameComparer = nameComparer;
qualifiedName = String.Concat(name, "Attribute");
fullyQualifiedName = String.Concat("NUnit.Framework.", name, "Attribute");
}
示例5: 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);
}
示例6: MapValues
public static Result<IEnumerable<SpecificationProperty>, Error> MapValues(
IEnumerable<SpecificationProperty> propertyTuples,
IEnumerable<KeyValuePair<string, IEnumerable<string>>> options,
Func<IEnumerable<string>, Type, bool, Maybe<object>> converter,
StringComparer comparer)
{
var sequencesAndErrors = propertyTuples
.Select(pt =>
options.FirstOrDefault(
s =>
s.Key.MatchName(((OptionSpecification)pt.Specification).ShortName, ((OptionSpecification)pt.Specification).LongName, comparer))
.ToMaybe()
.MapValueOrDefault(sequence =>
converter(sequence.Value, pt.Property.PropertyType, pt.Specification.TargetType != TargetType.Sequence)
.MapValueOrDefault(converted =>
Tuple.Create(
pt.WithValue(Maybe.Just(converted)),
Maybe.Nothing<Error>()),
Tuple.Create<SpecificationProperty, Maybe<Error>>(
pt,
Maybe.Just<Error>(new BadFormatConversionError(((OptionSpecification)pt.Specification).FromOptionSpecification())))),
Tuple.Create(pt, Maybe.Nothing<Error>()))
);
return Result.Succeed(
sequencesAndErrors.Select(se => se.Item1),
sequencesAndErrors.Select(se => se.Item2).OfType<Just<Error>>().Select(se => se.Value));
}
示例7: SisoEnvironment
static SisoEnvironment()
{
Formatting = new SisoDbFormatting();
StringConverter = new StringConverter(Formatting);
StringComparer = StringComparer.InvariantCultureIgnoreCase;
HashService = new Crc32HashService();
}
示例8: FieldDescriptor
/// <summary>
/// Initializes a new instance of the <see cref="FieldDescriptor" /> class.
/// </summary>
/// <param name="fieldInfo">The property information.</param>
/// <param name="defaultNameComparer">The default name comparer.</param>
/// <exception cref="System.ArgumentNullException">fieldInfo</exception>
public FieldDescriptor(FieldInfo fieldInfo, StringComparer defaultNameComparer)
: base(fieldInfo, defaultNameComparer)
{
if (fieldInfo == null) throw new ArgumentNullException("fieldInfo");
this.fieldInfo = fieldInfo;
}
示例9: 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;
}
}
}
}
示例10: SortLines
public void SortLines(IDocument document, int startLine, int endLine, StringComparer comparer, bool removeDuplicates)
{
List<string> lines = new List<string>();
for (int i = startLine; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(i);
lines.Add(document.GetText(line.Offset, line.Length));
}
lines.Sort(comparer);
if (removeDuplicates) {
lines = lines.Distinct(comparer).ToList();
}
using (document.OpenUndoGroup()) {
for (int i = 0; i < lines.Count; ++i) {
IDocumentLine line = document.GetLine(startLine + i);
document.Replace(line.Offset, line.Length, lines[i]);
}
// remove removed duplicate lines
for (int i = startLine + lines.Count; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(startLine + lines.Count);
document.Remove(line.Offset, line.TotalLength);
}
}
}
示例11: 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;
}
}
}
}
示例12: MapValues
MapValues(
IEnumerable<SpecificationProperty> propertyTuples,
IEnumerable<KeyValuePair<string, IEnumerable<string>>> options,
Func<IEnumerable<string>, System.Type, bool, Maybe<object>> converter,
StringComparer comparer)
{
var sequencesAndErrors = propertyTuples
.Select(pt =>
options.SingleOrDefault(
s =>
s.Key.MatchName(((OptionSpecification)pt.Specification).ShortName, ((OptionSpecification)pt.Specification).LongName, comparer))
.ToMaybe()
.Return(sequence =>
converter(sequence.Value, pt.Property.PropertyType, pt.Specification.ConversionType.IsScalar())
.Return(converted =>
Tuple.Create(
pt.WithValue(Maybe.Just(converted)),
Maybe.Nothing<Error>()),
Tuple.Create<SpecificationProperty, Maybe<Error>>(
pt,
Maybe.Just<Error>(new BadFormatConversionError(NameInfo.FromOptionSpecification((OptionSpecification)pt.Specification))))),
Tuple.Create(pt, Maybe.Nothing<Error>()))
);
return StatePair.Create(
sequencesAndErrors.Select(se => se.Item1),
sequencesAndErrors.Select(se => se.Item2).OfType<Just<Error>>().Select(se => se.Value));
}
示例13: SearchFileForm
/// <summary>
/// コンストラクタ
/// </summary>
public SearchFileForm()
{
InitializeComponent();
// リストビューのソートに関する設定
listViewFileNameSorter = new ListViewItemSorter();
listViewFileNameSorter.Column = 2;
listViewFileNameSorter.SortOrder = SortOrder.Ascending;
IComparer<string> ignoreCaseComparer = new StringComparer(false);
IComparer<string> ignoreCaseDirectoryComparer = new DirectoryComparer(false);
listViewFileNameSorter.Comparers.Add(ignoreCaseComparer);
listViewFileNameSorter.Comparers.Add(ignoreCaseComparer);
listViewFileNameSorter.Comparers.Add(ignoreCaseDirectoryComparer);
listViewFileName.ListViewItemSorter = listViewFileNameSorter;
listViewFileName.SetHeaderSortArrowStyle(
listViewFileNameSorter.Column,
SelectHeaderSortArrows(listViewFileNameSorter.SortOrder));
// 検索ディレクトリにシステムディレクトリのルートディレクトリを設定する
string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
if (!string.IsNullOrEmpty(systemPath))
{
textDirectory.Text = Path.GetPathRoot(systemPath);
}
}
示例14: Lookup
public static IEnumerable<Func<IEnumerable<string>, IEnumerable<Error>>> Lookup(StringComparer nameComparer)
{
return new List<Func<IEnumerable<string>, IEnumerable<Error>>>
{
HelpCommand(nameComparer)
};
}
示例15: Contains
public static NameLookupResult Contains(string name, IEnumerable<OptionSpecification> specifications, StringComparer comparer)
{
var option = specifications.FirstOrDefault(a => name.MatchName(a.ShortName, a.LongName, comparer));
if (option == null) return NameLookupResult.NoOptionFound;
return option.ConversionType == typeof(bool)
? NameLookupResult.BooleanOptionFound
: NameLookupResult.OtherOptionFound;
}