Пример #1
0
            private static bool IsNonNullReturnMethodCall(Expression memberAccess)
            {
                if (memberAccess.NodeType != Call)
                {
                    return(false);
                }

                var method = ((MethodCallExpression)memberAccess).Method;

                switch (method.Name)
                {
                case "ToString" when method.DeclaringType == typeof(object):
                case "Split" when method.DeclaringType == typeof(string):
                case "GetEnumerator" when method.DeclaringType.IsClosedTypeOf(typeof(IEnumerable <>)):
                    return(true);

                case "Select":
                case "SelectMany":
                case "Project":
                case "Filter":
                case "Where":
                case "OrderBy":
                case "OrderByDescending":
                case "ToList":
                case "ToArray":
                    return((method.DeclaringType == typeof(Enumerable)) ||
                           (method.DeclaringType == typeof(PublicEnumerableExtensions)));

                default:
                    return(false);
                }
            }
Пример #2
0
            private static bool IsNonNullReturnMethodCall(Expression memberAccess)
            {
                if (memberAccess.NodeType != Call)
                {
                    return(false);
                }

                var method = ((MethodCallExpression)memberAccess).Method;

                switch (method.Name)
                {
                case nameof(string.ToString) when method.DeclaringType == typeof(object):
                case nameof(string.Split) when method.DeclaringType == typeof(string):
                case nameof(IEnumerable <int> .GetEnumerator) when method.DeclaringType.IsClosedTypeOf(typeof(IEnumerable <>)):
                    return(true);

                case nameof(Enumerable.Select):
                case nameof(Enumerable.SelectMany):
                case nameof(PublicEnumerableExtensions.Project):
                case nameof(PublicEnumerableExtensions.Filter):
                case nameof(Enumerable.Where):
                case nameof(Enumerable.OrderBy):
                case nameof(Enumerable.OrderByDescending):
                case nameof(Enumerable.ToList):
                case nameof(Enumerable.ToArray):
                    return((method.DeclaringType == typeof(Enumerable)) ||
                           (method.DeclaringType == typeof(PublicEnumerableExtensions)));

                default:
                    return(false);
                }
            }