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


C# ImmutableArray.Contains方法代码示例

本文整理汇总了C#中ImmutableArray.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.Contains方法的具体用法?C# ImmutableArray.Contains怎么用?C# ImmutableArray.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImmutableArray的用法示例。


在下文中一共展示了ImmutableArray.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AnalyzeOperation

        private static void AnalyzeOperation(OperationAnalysisContext context, ImmutableArray<INamedTypeSymbol> taskTypes)
        {
            IAwaitExpression awaitExpression = context.Operation as IAwaitExpression;

            // Get the type of the expression being awaited and check it's a task type.
            ITypeSymbol typeOfAwaitedExpression = awaitExpression?.AwaitedValue?.Type;
            if (typeOfAwaitedExpression != null && taskTypes.Contains(typeOfAwaitedExpression.OriginalDefinition))
            {
                context.ReportDiagnostic(awaitExpression.AwaitedValue.Syntax.CreateDiagnostic(Rule));
            }
        }
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:11,代码来源:DoNotDirectlyAwaitATask.cs

示例2: Model

        private Model(
            DisconnectedBufferGraph disconnectedBufferGraph,
            CompletionList originalList,
            ImmutableArray<PresentationItem> totalItems,
            ImmutableArray<PresentationItem> filteredItems,
            PresentationItem selectedItem,
            ImmutableArray<CompletionItemFilter> completionItemFilters,
            ImmutableDictionary<CompletionItemFilter, bool> filterState,
            IReadOnlyDictionary<CompletionItem, string> completionItemToFilterText,
            bool isHardSelection,
            bool isUnique,
            bool useSuggestionMode,
            PresentationItem suggestionModeItem,
            PresentationItem defaultSuggestionModeItem,
            CompletionTrigger trigger,
            ITrackingPoint commitSpanEndPoint,
            bool dismissIfEmpty)
        {
            Contract.ThrowIfNull(selectedItem);
            Contract.ThrowIfFalse(totalItems.Length != 0, "Must have at least one item.");
            Contract.ThrowIfFalse(filteredItems.Length != 0, "Must have at least one filtered item.");
            Contract.ThrowIfFalse(filteredItems.Contains(selectedItem) || defaultSuggestionModeItem == selectedItem, "Selected item must be in filtered items.");

            _disconnectedBufferGraph = disconnectedBufferGraph;
            this.OriginalList = originalList;
            this.TotalItems = totalItems;
            this.FilteredItems = filteredItems;
            this.FilterState = filterState;
            this.SelectedItem = selectedItem;
            this.CompletionItemFilters = completionItemFilters;
            this.CompletionItemToFilterText = completionItemToFilterText;
            this.IsHardSelection = isHardSelection;
            this.IsUnique = isUnique;
            this.UseSuggestionMode = useSuggestionMode;
            this.SuggestionModeItem = suggestionModeItem;
            this.DefaultSuggestionModeItem = defaultSuggestionModeItem;
            this.Trigger = trigger;
            this.CommitTrackingSpanEndPoint = commitSpanEndPoint;
            this.DismissIfEmpty = dismissIfEmpty;
        }
开发者ID:rgani,项目名称:roslyn,代码行数:40,代码来源:Model.cs

示例3: 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

示例4: GetAssemblyObjects

        // Internal for testing.
        internal static IEnumerable<FusionAssemblyIdentity.IAssemblyName> GetAssemblyObjects(
            FusionAssemblyIdentity.IAssemblyName partialNameFilter,
            ImmutableArray<ProcessorArchitecture> architectureFilter)
        {
            IAssemblyEnum enumerator;
            FusionAssemblyIdentity.IApplicationContext applicationContext = null;

            int hr = CreateAssemblyEnum(out enumerator, applicationContext, partialNameFilter, ASM_CACHE.GAC, IntPtr.Zero);
            if (hr == S_FALSE)
            {
                // no assembly found
                yield break;
            }
            else if (hr != S_OK)
            {
                Exception e = Marshal.GetExceptionForHR(hr);
                if (e is FileNotFoundException)
                {
                    // invalid assembly name:
                    yield break;
                }
                else if (e != null)
                {
                    throw e;
                }
                else
                {
                    // for some reason it might happen that CreateAssemblyEnum returns non-zero HR that doesn't correspond to any exception:
                    throw new ArgumentException("Invalid assembly name".NeedsLocalization());
                }
            }

            while (true)
            {
                FusionAssemblyIdentity.IAssemblyName nameObject;

                hr = enumerator.GetNextAssembly(out applicationContext, out nameObject, 0);
                if (hr != 0)
                {
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    break;
                }

                if (!architectureFilter.IsDefault)
                {
                    var assemblyArchitecture = FusionAssemblyIdentity.GetProcessorArchitecture(nameObject);
                    if (!architectureFilter.Contains(assemblyArchitecture))
                    {
                        continue;
                    }
                }

                yield return nameObject;
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:60,代码来源:GlobalAssemblyCache.cs

示例5: AnalyzeInvocationForIgnoredReturnValue

        public void AnalyzeInvocationForIgnoredReturnValue(SyntaxNodeAnalysisContext context, ImmutableArray<INamedTypeSymbol> immutableTypeSymbols)
        {
            SemanticModel model = context.SemanticModel;
            var candidateInvocation = (InvocationExpressionSyntax)context.Node;

            //We're looking for invocations that are direct children of expression statements
            if (!(candidateInvocation.Parent.IsKind(SyntaxKind.ExpressionStatement)))
            {
                return;
            }

            //If we can't find the method symbol, quit
            var methodSymbol = model.GetSymbolInfo(candidateInvocation).Symbol as IMethodSymbol;
            if (methodSymbol == null)
            {
                return;
            }

            //If the method doesn't start with something like "With" or "Replace", quit
            string methodName = methodSymbol.Name;
            if (!s_immutableMethodNames.Any(n => methodName.StartsWith(n, StringComparison.Ordinal)))
            {
                return;
            }

            //If we're not in one of the known immutable types, quit
            var parentType = methodSymbol.ReceiverType as INamedTypeSymbol;
            if (parentType == null)
            {
                return;
            }

            var baseTypesAndSelf = methodSymbol.ReceiverType.GetBaseTypes().ToList();
            baseTypesAndSelf.Add(parentType);

            if (!baseTypesAndSelf.Any(n => immutableTypeSymbols.Contains(n)))
            {
                return;
            }

            Location location = candidateInvocation.GetLocation();
            Diagnostic diagnostic = Diagnostic.Create(DoNotIgnoreReturnValueDiagnosticRule, location, methodSymbol.ReceiverType.Name, methodSymbol.Name);
            context.ReportDiagnostic(diagnostic);
        }
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:44,代码来源:CSharpImmutableObjectMethodAnalyzer.cs

示例6: VerifyAssemblyReferences

 private static void VerifyAssemblyReferences(
     MetadataReference target,
     ImmutableArray<MetadataReference> references,
     ImmutableArray<AssemblyIdentity> expectedIdentities)
 {
     Assert.True(references.Contains(target));
     var modules = references.SelectAsArray(r => r.ToModuleInstance());
     using (var runtime = new RuntimeInstance(modules))
     {
         var moduleVersionId = target.GetModuleVersionId();
         var blocks = runtime.Modules.SelectAsArray(m => m.MetadataBlock);
         var actualReferences = blocks.MakeAssemblyReferences(moduleVersionId, CompilationExtensions.IdentityComparer);
         // Verify identities.
         var actualIdentities = actualReferences.SelectAsArray(r => r.GetAssemblyIdentity());
         AssertEx.Equal(expectedIdentities, actualIdentities);
         // Verify identities are unique.
         var uniqueIdentities = actualIdentities.Distinct();
         Assert.Equal(actualIdentities.Length, uniqueIdentities.Length);
     }
 }
开发者ID:MischkowskyM,项目名称:roslyn,代码行数:20,代码来源:ReferencedModulesTests.cs

示例7: GenerateBraceFixes

        private static Dictionary<SyntaxToken, SyntaxToken> GenerateBraceFixes(Document document, ImmutableArray<SyntaxToken> braceTokens)
        {
            var tokenReplacements = new Dictionary<SyntaxToken, SyntaxToken>();

            foreach (var braceToken in braceTokens)
            {
                var braceLine = LocationHelpers.GetLineSpan(braceToken).StartLinePosition.Line;
                var braceReplacementToken = braceToken;

                var indentationOptions = IndentationOptions.FromDocument(document);
                var indentationSteps = DetermineIndentationSteps(indentationOptions, braceToken);

                var previousToken = braceToken.GetPreviousToken();
                var nextToken = braceToken.GetNextToken();

                if (IsAccessorWithSingleLineBlock(previousToken, braceToken))
                {
                    var newTrailingTrivia = previousToken.TrailingTrivia
                        .WithoutTrailingWhitespace()
                        .Add(SyntaxFactory.Space);

                    AddReplacement(tokenReplacements, previousToken, previousToken.WithTrailingTrivia(newTrailingTrivia));

                    braceReplacementToken = braceReplacementToken.WithLeadingTrivia(braceToken.LeadingTrivia.WithoutLeadingWhitespace());
                }
                else
                {
                    // Check if we need to apply a fix before the brace
                    if (LocationHelpers.GetLineSpan(previousToken).StartLinePosition.Line == braceLine)
                    {
                        if (!braceTokens.Contains(previousToken))
                        {
                            var sharedTrivia = braceReplacementToken.LeadingTrivia.WithoutTrailingWhitespace();
                            var previousTokenNewTrailingTrivia = previousToken.TrailingTrivia
                            .WithoutTrailingWhitespace()
                            .AddRange(sharedTrivia)
                            .Add(SyntaxFactory.CarriageReturnLineFeed);

                            AddReplacement(tokenReplacements, previousToken, previousToken.WithTrailingTrivia(previousTokenNewTrailingTrivia));
                        }

                        braceReplacementToken = braceReplacementToken.WithLeadingTrivia(IndentationHelper.GenerateWhitespaceTrivia(indentationOptions, indentationSteps));
                    }

                    // Check if we need to apply a fix after the brace
                    // if a closing brace is followed by a semi-colon or closing paren, no fix is needed.
                    if ((LocationHelpers.GetLineSpan(nextToken).StartLinePosition.Line == braceLine) &&
                        (!braceToken.IsKind(SyntaxKind.CloseBraceToken) || !IsValidFollowingToken(nextToken)))
                    {
                        var sharedTrivia = nextToken.LeadingTrivia.WithoutTrailingWhitespace();
                        var newTrailingTrivia = braceReplacementToken.TrailingTrivia
                            .WithoutTrailingWhitespace()
                            .AddRange(sharedTrivia)
                            .Add(SyntaxFactory.CarriageReturnLineFeed);

                        if (!braceTokens.Contains(nextToken))
                        {
                            int newIndentationSteps;
                            if (braceToken.IsKind(SyntaxKind.OpenBraceToken))
                            {
                                newIndentationSteps = indentationSteps + 1;
                            }
                            else if (nextToken.IsKind(SyntaxKind.CloseBraceToken))
                            {
                                newIndentationSteps = Math.Max(0, indentationSteps - 1);
                            }
                            else
                            {
                                newIndentationSteps = indentationSteps;
                            }

                            AddReplacement(tokenReplacements, nextToken, nextToken.WithLeadingTrivia(IndentationHelper.GenerateWhitespaceTrivia(indentationOptions, newIndentationSteps)));
                        }

                        braceReplacementToken = braceReplacementToken.WithTrailingTrivia(newTrailingTrivia);
                    }
                }

                AddReplacement(tokenReplacements, braceToken, braceReplacementToken);
            }

            return tokenReplacements;
        }
开发者ID:neugenes,项目名称:StyleCopAnalyzers,代码行数:83,代码来源:SA1500CodeFixProvider.cs

示例8: VerifyAssemblyReferences

 private static void VerifyAssemblyReferences(
     MetadataReference target,
     ImmutableArray<MetadataReference> references,
     ImmutableArray<AssemblyIdentity> expectedIdentities)
 {
     Assert.True(references.Contains(target));
     var modules = references.SelectAsArray(r => r.ToModuleInstance(fullImage: null, symReader: null, includeLocalSignatures: false));
     using (var runtime = new RuntimeInstance(modules))
     {
         var moduleVersionId = target.GetModuleVersionId();
         var blocks = runtime.Modules.SelectAsArray(m => m.MetadataBlock);
         var actualReferences = blocks.MakeAssemblyReferences(moduleVersionId, Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.CompilationExtensions.IdentityComparer);
         // Verify identities.
         var actualIdentities = actualReferences.SelectAsArray(r => r.GetAssemblyIdentity());
         AssertEx.Equal(expectedIdentities, actualIdentities);
         // Verify identities are unique.
         var uniqueIdentities = actualIdentities.Distinct();
         Assert.Equal(actualIdentities.Length, uniqueIdentities.Length);
     }
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:20,代码来源:ReferencedModulesTests.cs

示例9: GetEffectiveIncludesCore

        private void GetEffectiveIncludesCore(ImmutableArray<string>.Builder arrayBuilder)
        {
            arrayBuilder.Add(this.FilePath);

            foreach (var ruleSetInclude in _includes)
            {
                var ruleSet = ruleSetInclude.LoadRuleSet(this);

                // If we couldn't load the ruleset file, then there's nothing to do.
                if (ruleSet == null)
                {
                    continue;
                }

                // If this file has already been included don't recurse into it.
                if (!arrayBuilder.Contains(ruleSet.FilePath, StringComparer.OrdinalIgnoreCase))
                {
                    ruleSet.GetEffectiveIncludesCore(arrayBuilder);
                }
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:21,代码来源:RuleSet.cs

示例10: VerifyFixAsync

        private async static Task VerifyFixAsync(string language, ImmutableArray<string> diagnosticIds, CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics, LanguageVersion languageVersionCSharp, Microsoft.CodeAnalysis.VisualBasic.LanguageVersion languageVersionVB)
        {
            var document = CreateDocument(oldSource, language, languageVersionCSharp, languageVersionVB);
            var compilerDiagnostics = (await GetCompilerDiagnosticsAsync(document).ConfigureAwait(true)).ToList();
            var analyzerDiagnostics = compilerDiagnostics.Where(c => diagnosticIds.Contains(c.Id)).ToList();
            var attempts = analyzerDiagnostics.Count;

            for (int i = 0; i < attempts; ++i)
            {
                var actions = new List<CodeAction>();
                var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
                await codeFixProvider.RegisterCodeFixesAsync(context).ConfigureAwait(true);

                if (!actions.Any()) break;

                if (codeFixIndex != null)
                    document = await ApplyFixAsync(document, actions.ElementAt((int)codeFixIndex)).ConfigureAwait(true);
                else
                    document = await ApplyFixAsync(document, actions.ElementAt(0)).ConfigureAwait(true);

                var newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, await GetCompilerDiagnosticsAsync(document).ConfigureAwait(true));
                compilerDiagnostics = (await GetCompilerDiagnosticsAsync(document).ConfigureAwait(true)).ToList();
                analyzerDiagnostics = compilerDiagnostics.Where(c => diagnosticIds.Contains(c.Id)).ToList();

                //check if applying the code fix introduced any new compiler diagnostics
                if (!allowNewCompilerDiagnostics && newCompilerDiagnostics.Any())
                {
                    // Format and get the compiler diagnostics again so that the locations make sense in the output
                    document = document.WithSyntaxRoot(Formatter.Format(await document.GetSyntaxRootAsync().ConfigureAwait(true), Formatter.Annotation, document.Project.Solution.Workspace));
                    newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, await GetCompilerDiagnosticsAsync(document).ConfigureAwait(true));

                    Assert.True(false, $"Fix introduced new compiler diagnostics:\r\n{string.Join("\r\n", newCompilerDiagnostics.Select(d => d.ToString()))}\r\n\r\nNew document:\r\n{(await document.GetSyntaxRootAsync().ConfigureAwait(true)).ToFullString()}\r\n");
                }

                //check if there are analyzer diagnostics left after the code fix
                if (!analyzerDiagnostics.Any()) break;
            }

            //after applying all of the code fixes, compare the resulting string to the inputted one
            var actual = await GetStringFromDocumentAsync(document).ConfigureAwait(true);
            Assert.Equal(newSource, actual);
        }
开发者ID:Cadums01,项目名称:code-cracker,代码行数:42,代码来源:CodeFixVerifier.cs

示例11: GetUsedParameters

 private static IImmutableSet<IParameterSymbol> GetUsedParameters(ImmutableArray<IParameterSymbol> parameters, SyntaxNode body, SemanticModel semanticModel)
 {
     return body.DescendantNodes()
                .Where(n => n.IsKind(SyntaxKind.IdentifierName))
                .Select(identierName => semanticModel.GetSymbolInfo(identierName).Symbol as IParameterSymbol)
                .Where(symbol => symbol != null && parameters.Contains(symbol))
                .ToImmutableHashSet();
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:8,代码来源:MethodParameterUnused.cs

示例12: GetAccessibility

 private static Accessibility GetAccessibility(ImmutableArray<string> tags)
 {
     if (tags.Contains(CompletionTags.Public))
     {
         return Accessibility.Public;
     }
     else if (tags.Contains(CompletionTags.Protected))
     {
         return Accessibility.Protected;
     }
     else if (tags.Contains(CompletionTags.Internal))
     {
         return Accessibility.Internal;
     }
     else if (tags.Contains(CompletionTags.Private))
     {
         return Accessibility.Private;
     }
     else
     {
         return Accessibility.NotApplicable;
     }
 }
开发者ID:abock,项目名称:roslyn,代码行数:23,代码来源:GlyphExtensions.cs

示例13: GetLanguage

		static Language GetLanguage(ImmutableArray<string> tags) {
			if (tags.Contains(LanguageNames.CSharp))
				return Language.CSharp;
			if (tags.Contains(LanguageNames.VisualBasic))
				return Language.VisualBasic;
			return Language.None;
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:7,代码来源:CompletionKind.cs

示例14: GetAccessibility

		static Accessibility GetAccessibility(ImmutableArray<string> tags) {
			if (tags.Contains(CompletionTags.Public))
				return Accessibility.Public;
			if (tags.Contains(CompletionTags.Protected))
				return Accessibility.Protected;
			if (tags.Contains(CompletionTags.Internal))
				return Accessibility.Internal;
			if (tags.Contains(CompletionTags.Private))
				return Accessibility.Private;
			return Accessibility.None;
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:11,代码来源:CompletionKind.cs

示例15: GetAssemblyIdentitiesAndPaths

        private static IEnumerable<Tuple<AssemblyIdentity, string>> GetAssemblyIdentitiesAndPaths(string name, Version version, string publicKeyToken, ImmutableArray<ProcessorArchitecture> architectureFilter)
        {
            foreach (string gacPath in RootLocations)
            {
                var assemblyPaths = (name == "mscorlib") ?
                    GetCorlibPaths(version) :
                    GetGacAssemblyPaths(gacPath, name, version, publicKeyToken);

                foreach (var assemblyPath in assemblyPaths)
                {
                    if (!File.Exists(assemblyPath))
                    {
                        continue;
                    }

                    var gacAssemblyName = new AssemblyName(assemblyPath);

                    if (gacAssemblyName.ProcessorArchitecture != ProcessorArchitecture.None &&
                        architectureFilter != default(ImmutableArray<ProcessorArchitecture>) &&
                        architectureFilter.Length > 0 &&
                        !architectureFilter.Contains(gacAssemblyName.ProcessorArchitecture))
                    {
                        continue;
                    }

                    var assemblyIdentity = new AssemblyIdentity(
                        gacAssemblyName.Name,
                        gacAssemblyName.Version,
                        gacAssemblyName.CultureName,
                        ImmutableArray.Create(gacAssemblyName.GetPublicKeyToken()));

                    yield return new Tuple<AssemblyIdentity, string>(assemblyIdentity, assemblyPath);
                }
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:35,代码来源:MonoGlobalAssemblyCache.cs


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