本文整理汇总了C#中ImmutableArray.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.IndexOf方法的具体用法?C# ImmutableArray.IndexOf怎么用?C# ImmutableArray.IndexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableArray
的用法示例。
在下文中一共展示了ImmutableArray.IndexOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRecentItemIndex
private static int GetRecentItemIndex(ImmutableArray<string> recentItems, CompletionItem item)
{
var index = recentItems.IndexOf(item.DisplayText);
return -index;
}
示例2: HandleElement
private static void HandleElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax element, ImmutableArray<string> parentTypeParameters, int index, Location alternativeDiagnosticLocation)
{
var nameAttribute = XmlCommentHelper.GetFirstAttributeOrDefault<XmlNameAttributeSyntax>(element);
// Make sure we ignore violations that should be reported by SA1613 instead.
if (string.IsNullOrWhiteSpace(nameAttribute?.Identifier?.Identifier.ValueText))
{
return;
}
if (!parentTypeParameters.Contains(nameAttribute.Identifier.Identifier.ValueText))
{
context.ReportDiagnostic(Diagnostic.Create(MissingTypeParameterDescriptor, nameAttribute?.Identifier?.GetLocation() ?? alternativeDiagnosticLocation, nameAttribute.Identifier.Identifier.ValueText));
}
else if (parentTypeParameters.Length <= index || parentTypeParameters[index] != nameAttribute.Identifier.Identifier.ValueText)
{
context.ReportDiagnostic(
Diagnostic.Create(
OrderDescriptor,
nameAttribute?.Identifier?.GetLocation() ?? alternativeDiagnosticLocation,
nameAttribute.Identifier.Identifier.ValueText,
parentTypeParameters.IndexOf(nameAttribute.Identifier.Identifier.ValueText) + 1));
}
}
开发者ID:neugenes,项目名称:StyleCopAnalyzers,代码行数:24,代码来源:SA1620GenericTypeParameterDocumentationMustMatchTypeParameters.cs
示例3: WithInheritsFrom
private static ImmutableArray<SymbolDisplayPart> WithInheritsFrom(ImmutableArray<SymbolDisplayPart> defaultParts, IEnumerable<SymbolDisplayPart> inheritanceSuffix)
{
var spaceBeforeFirstTypeConstraint = defaultParts.IndexOf(new SymbolDisplayPart(SymbolDisplayPartKind.Keyword, null, "where")) - 1;
var locationToInsert = spaceBeforeFirstTypeConstraint >= 0 ? spaceBeforeFirstTypeConstraint : defaultParts.Count();
return defaultParts.InsertRange(locationToInsert, inheritanceSuffix);
}
示例4: HandleMemberList
private static void HandleMemberList(SyntaxNodeAnalysisContext context, ImmutableArray<OrderingTrait> elementOrder, int kindIndex, SyntaxList<MemberDeclarationSyntax> members, ImmutableArray<SyntaxKind> order)
{
for (int i = 0; i < members.Count - 1; i++)
{
if (members[i + 1].IsKind(SyntaxKind.IncompleteMember))
{
i++;
continue;
}
if (members[i].IsKind(SyntaxKind.IncompleteMember))
{
continue;
}
bool compareKind = true;
for (int j = 0; compareKind && j < kindIndex; j++)
{
switch (elementOrder[j])
{
case OrderingTrait.Accessibility:
if (MemberOrderHelper.GetAccessLevelForOrdering(members[i + 1], members[i + 1].GetModifiers())
!= MemberOrderHelper.GetAccessLevelForOrdering(members[i], members[i].GetModifiers()))
{
compareKind = false;
}
continue;
case OrderingTrait.Constant:
case OrderingTrait.Readonly:
// Only fields may be marked const or readonly, and all fields have the same kind.
continue;
case OrderingTrait.Static:
bool currentIsStatic = members[i].GetModifiers().Any(SyntaxKind.StaticKeyword);
bool nextIsStatic = members[i + 1].GetModifiers().Any(SyntaxKind.StaticKeyword);
if (currentIsStatic != nextIsStatic)
{
compareKind = false;
}
continue;
case OrderingTrait.Kind:
default:
continue;
}
}
if (!compareKind)
{
continue;
}
var elementSyntaxKind = members[i].Kind();
elementSyntaxKind = elementSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : elementSyntaxKind;
int index = order.IndexOf(elementSyntaxKind);
var nextElementSyntaxKind = members[i + 1].Kind();
nextElementSyntaxKind = nextElementSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : nextElementSyntaxKind;
int nextIndex = order.IndexOf(nextElementSyntaxKind);
if (index > nextIndex)
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, NamedTypeHelpers.GetNameOrIdentifierLocation(members[i + 1]), MemberNames[nextElementSyntaxKind], MemberNames[elementSyntaxKind]));
}
}
}
示例5: DeriveArguments
internal static ImmutableArray<IArgument> DeriveArguments(ImmutableArray<BoundExpression> boundArguments, ImmutableArray<string> argumentNames, ImmutableArray<int> argumentsToParameters, ImmutableArray<RefKind> argumentRefKinds, ImmutableArray<Symbols.ParameterSymbol> parameters)
{
ArrayBuilder<IArgument> arguments = ArrayBuilder<IArgument>.GetInstance(boundArguments.Length);
for (int parameterIndex = 0; parameterIndex < parameters.Length; parameterIndex++)
{
int argumentIndex = -1;
if (argumentsToParameters.IsDefault)
{
argumentIndex = parameterIndex;
}
else
{
argumentIndex = argumentsToParameters.IndexOf(parameterIndex);
}
if (argumentIndex == -1)
{
// No argument has been supplied for the parameter.
Symbols.ParameterSymbol parameter = parameters[parameterIndex];
if (parameter.HasExplicitDefaultValue)
{
arguments.Add(new Argument(ArgumentKind.DefaultValue, parameter, new Literal(parameter.ExplicitDefaultConstantValue, parameter.Type, null)));
}
else
{
arguments.Add(null);
}
}
else
{
arguments.Add(DeriveArgument(parameterIndex, argumentIndex, boundArguments, argumentNames, argumentRefKinds, parameters));
}
}
return arguments.ToImmutableAndFree();
}
示例6: HandleMemberList
private static void HandleMemberList(SyntaxNodeAnalysisContext context, SyntaxList<MemberDeclarationSyntax> members, ImmutableArray<SyntaxKind> order)
{
for (int i = 0; i < members.Count - 1; i++)
{
if (members[i + 1].IsKind(SyntaxKind.IncompleteMember))
{
i++;
continue;
}
if (members[i].IsKind(SyntaxKind.IncompleteMember))
{
continue;
}
var elementSyntaxKind = members[i].Kind();
elementSyntaxKind = elementSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : elementSyntaxKind;
int index = order.IndexOf(elementSyntaxKind);
var nextElementSyntaxKind = members[i + 1].Kind();
nextElementSyntaxKind = nextElementSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : nextElementSyntaxKind;
int nextIndex = order.IndexOf(nextElementSyntaxKind);
if (index > nextIndex)
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, NamedTypeHelpers.GetNameOrIdentifierLocation(members[i + 1]), MemberNames[nextElementSyntaxKind], MemberNames[elementSyntaxKind]));
}
}
}
示例7: DeriveArguments
internal static ImmutableArray<IArgument> DeriveArguments(ImmutableArray<BoundExpression> boundArguments, ImmutableArray<string> argumentNames, ImmutableArray<int> argumentsToParameters, ImmutableArray<RefKind> argumentRefKinds, ImmutableArray<Symbols.ParameterSymbol> parameters)
{
ArrayBuilder<IArgument> arguments = ArrayBuilder<IArgument>.GetInstance(boundArguments.Length);
for (int parameterIndex = 0; parameterIndex < parameters.Length; parameterIndex++)
{
int argumentIndex = -1;
if (argumentsToParameters.IsDefault)
{
argumentIndex = parameterIndex;
}
else
{
argumentIndex = argumentsToParameters.IndexOf(parameterIndex);
}
// No argument has been supplied for the parameter at `parameterIndex`:
// 1. `argumentIndex == -1' when the arguments are specified out of parameter order, and no argument is provided for parameter corresponding to `parameters[parameterIndex]`.
// 2. `argumentIndex >= boundArguments.Length` when the arguments are specified in parameter order, and no argument is provided at `parameterIndex`.
if (argumentIndex == -1 || argumentIndex >= boundArguments.Length)
{
Symbols.ParameterSymbol parameter = parameters[parameterIndex];
// Corresponding parameter is optional with default value.
if (parameter.HasExplicitDefaultValue)
{
arguments.Add(new Argument(ArgumentKind.DefaultValue, parameter, new Literal(parameter.ExplicitDefaultConstantValue, parameter.Type, null)));
}
else
{
// If corresponding parameter is Param array, then this means 0 element is provided and an Argument of kind == ParamArray will be added,
// otherwise it is an error and null is added.
arguments.Add(DeriveArgument(parameterIndex, argumentIndex, boundArguments, argumentNames, argumentRefKinds, parameters));
}
}
else
{
arguments.Add(DeriveArgument(parameterIndex, argumentIndex, boundArguments, argumentNames, argumentRefKinds, parameters));
}
}
return arguments.ToImmutableAndFree();
}