コード例 #1
0
        public static bool IsAsyncSuffixMissing(IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration.IsOverride) return false;

            var declaredElement = methodDeclaration.DeclaredElement;
            if (declaredElement != null)
            {
                var settings = methodDeclaration.GetSettingsStore();
                var excludeTestMethods = settings.GetValue(AsyncSuffixSettingsAccessor.ExcludeTestMethodsFromAnalysis);
                if (excludeTestMethods)
                {
                    if (IsAnnotatedWithKnownTestAttribute(methodDeclaration))
                    {
                        return false;
                    }
                }

                if (declaredElement.ShortName.EndsWith("Async", StringComparison.Ordinal))
                {
                    return false;
                }

                var returnType = declaredElement.ReturnType as IDeclaredType;
                if (returnType != null)
                {
                    if (returnType.IsTaskType())
                    {
                        return true;
                    }
                }
            }
            return false;
        }
コード例 #2
0
        public bool SkipRename(IMethodDeclaration method)
        {
            var excludeTestMethods = method.GetSettingsStore().GetValue(AsyncConverterSettingsAccessor.ExcludeTestMethodsFromRenaming);

            return(excludeTestMethods &&
                   underTestChecker.IsUnder(method));
        }
コード例 #3
0
        public static bool IsAsyncSuffixMissing(this IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration.IsOverride)
            {
                return(false);
            }
            var declaredElement = methodDeclaration.DeclaredElement;

            if (declaredElement != null)
            {
                var memberInstances = declaredElement.GetAllSuperMembers();
                if (memberInstances.Count > 0)
                {
                    return(false);
                }

                var settings           = methodDeclaration.GetSettingsStore();
                var excludeTestMethods = settings.GetValue(AsyncSuffixSettingsAccessor.ExcludeTestMethodsFromAnalysis);
                if (excludeTestMethods)
                {
                    if (declaredElement.IsTestMethod() || methodDeclaration.IsAnnotatedWithKnownTestAttribute())
                    {
                        return(false);
                    }
                }

                if (declaredElement.ShortName.EndsWith("Async", StringComparison.Ordinal))
                {
                    return(false);
                }

                var returnType = declaredElement.ReturnType as IDeclaredType;
                if (returnType == null)
                {
                    return(false);
                }

                var customAsyncTypeNames = settings.EnumEntryIndices(AsyncSuffixSettingsAccessor.CustomAsyncTypes)
                                           .ToArray();
                var customAsyncTypes = new List <IDeclaredType>();
                customAsyncTypeNames
                .ForEach(type => customAsyncTypes.Add(TypeFactory.CreateTypeByCLRName(type, declaredElement.Module)));

                var returnTypeElement = returnType.GetTypeElement();
                var isCustomAsyncType = returnTypeElement != null && customAsyncTypes.Any(type => returnTypeElement.IsDescendantOf(type.GetTypeElement()));

                if (returnType.IsTaskType() || isCustomAsyncType)
                {
                    return(true);
                }
            }
            return(false);
        }