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


C# System.Collections.Immutable.Contains方法代码示例

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


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

示例1: IsTestMethod

        private static bool IsTestMethod(MethodDeclarationSyntax method)
        {
            var methodAttributes = new[] { "Test", "TestMethod", "Fact" };
            var attributes = method.AttributeLists.FirstOrDefault()?.Attributes;

            if (attributes == null)
            {
                return false;
            }

            return attributes.Value.Any(x => methodAttributes.Contains(x.Name.ToString()));
        }
开发者ID:nemec,项目名称:VSDiagnostics,代码行数:12,代码来源:TestMethodWithoutPublicModifierAnalyzer.cs

示例2: AnalyzeSymbol

        private void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
        {
            var argumentList = (GenericNameSyntax) context.Node;
            var identifier = "Unnamed variable";
            var ancestorNodes = new[] { SyntaxKind.LocalDeclarationStatement, SyntaxKind.FieldDeclaration, SyntaxKind.Parameter, SyntaxKind.PropertyDeclaration };
            var parentNode = context.Node.AncestorsAndSelf().FirstOrDefault(x => ancestorNodes.Contains(x.Kind()));

            // We're having a return type
            if (context.Node.Parent is MethodDeclarationSyntax)
            {
                identifier = "Return statement";
            }

            if (parentNode != null)
            {
                switch (parentNode.Kind())
                {
                    case SyntaxKind.LocalDeclarationStatement:
                    {
                        identifier = ((LocalDeclarationStatementSyntax) parentNode).Declaration?.Variables.FirstOrDefault()?.Identifier.Text;
                        break;
                    }
                    case SyntaxKind.FieldDeclaration:
                    {
                        identifier = ((FieldDeclarationSyntax) parentNode).Declaration?.Variables.FirstOrDefault()?.Identifier.Text;
                        break;
                    }
                    case SyntaxKind.Parameter:
                    {
                        identifier = ((ParameterSyntax) parentNode).Identifier.Text;
                        break;
                    }
                    case SyntaxKind.TypeParameter:
                    {
                        identifier = ((TypeParameterSyntax) parentNode).Identifier.Text;
                        break;
                    }
                    case SyntaxKind.PropertyDeclaration:
                    {
                        identifier = ((PropertyDeclarationSyntax) parentNode).Identifier.Text;
                        break;
                    }
                }
            }

            Handle(identifier, context.Node.GetLocation(), argumentList, context);
        }
开发者ID:nemec,项目名称:VSDiagnostics,代码行数:47,代码来源:NullableToShorthandAnalyzer.cs

示例3: Initialize

        public override void Initialize(AnalysisContext analysisContext)
        {
            analysisContext.RegisterCompilationStartAction(
                compilationStartAnalysisContext =>
                {
                    Compilation compilation = compilationStartAnalysisContext.Compilation;

                    INamedTypeSymbol[] nativeResourceTypes = new[]
                    {
                        WellKnownTypes.IntPtr(compilation),
                        WellKnownTypes.UIntPtr(compilation),
                        WellKnownTypes.HandleRef(compilation)
                    };

                    compilationStartAnalysisContext.RegisterOperationAction(
                        operationAnalysisContext =>
                        {
                            var assignment = (IAssignmentExpression)operationAnalysisContext.Operation;

                            IReferenceExpression target = assignment.Target;
                            if (target == null)
                            {
                                // This can happen if the left-hand side is an undefined symbol.
                                return;
                            }

                            if (target.Kind != OperationKind.FieldReferenceExpression)
                            {
                                return;
                            }

                            var fieldReference = (IFieldReferenceExpression)target;
                            var field = fieldReference.Member as IFieldSymbol;
                            if (field == null || field.Kind != SymbolKind.Field || field.IsStatic)
                            {
                                return;
                            }

                            if (!nativeResourceTypes.Contains(field.Type))
                            {
                                return;
                            }

                            INamedTypeSymbol containingType = field.ContainingType;
                            if (containingType == null || containingType.IsValueType)
                            {
                                return;
                            }

                            if (!containingType.AllInterfaces.Contains(WellKnownTypes.IDisposable(compilation)))
                            {
                                return;
                            }

                            if (containingType.HasFinalizer())
                            {
                                return;
                            }

                            if (assignment.Value == null || assignment.Value.Kind != OperationKind.InvocationExpression)
                            {
                                return;
                            }

                            var invocation = (IInvocationExpression)assignment.Value;
                            if (invocation == null)
                            {
                                return;
                            }

                            IMethodSymbol method = invocation.TargetMethod;

                            // TODO: What about COM?
                            if (method.GetDllImportData() == null)
                            {
                                return;
                            }

                            operationAnalysisContext.ReportDiagnostic(containingType.CreateDiagnostic(Rule));
                        },
                        OperationKind.AssignmentExpression);
                });
        }
开发者ID:hanin,项目名称:roslyn-analyzers,代码行数:83,代码来源:DisposableTypesShouldDeclareFinalizer.cs


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