Пример #1
0
        private static bool IsExcludedFromCodeCoverage(MethodSymbol method)
        {
            var containingType = method.ContainingType;
            while ((object)containingType != null)
            {
                if (containingType.IsDirectlyExcludedFromCodeCoverage)
                {
                    return true;
                }

                containingType = containingType.ContainingType;
            }

            // Skip lambdas and local functions. They can't have custom attributes.
            var nonLambda = method.ContainingNonLambdaMember();
            if (nonLambda?.Kind == SymbolKind.Method)
            {
                method = (MethodSymbol)nonLambda;

                if (method.IsDirectlyExcludedFromCodeCoverage)
                {
                    return true;
                }

                var associatedSymbol = method.AssociatedSymbol;
                switch (associatedSymbol?.Kind)
                {
                    case SymbolKind.Property:
                        if (((PropertySymbol)associatedSymbol).IsDirectlyExcludedFromCodeCoverage)
                        {
                            return true;
                        }
                        break;

                    case SymbolKind.Event:
                        if (((EventSymbol)associatedSymbol).IsDirectlyExcludedFromCodeCoverage)
                        {
                            return true;
                        }
                        break;
                }
            }

            return false;
        }