Пример #1
0
        private static void ThrowIfHasErrors(this TypeErrors errors, MemberSettings settings, string className, string methodName)
        {
            if (errors == null)
            {
                return;
            }

            if (errors.Errors.Count == 1 && ReferenceEquals(errors.Errors[0], RequiresReferenceHandling.ComplexType))
            {
                return;
            }

            var errorBuilder = new StringBuilder();

            errorBuilder.AppendFailed(className, methodName)
            .AppendNotSupported(errors)
            .AppendSolveTheProblemBy()
            .AppendSuggestEquatable(errors)
            .AppendLine($"* Use {settings.GetType().Name} and specify how comparing is performed:")
            .AppendSuggestReferenceHandling(errors, settings)
            .AppendSuggestExclude(errors);

            var message = errorBuilder.ToString();

            throw new NotSupportedException(message);
        }
Пример #2
0
        // ReSharper disable once UnusedParameter.Local
        private static string GetErrorText(this TypeErrors errors, MemberSettings settings, string className, string methodName)
        {
            var errorBuilder = new StringBuilder();
            errorBuilder.AppendCopyFailed(className, methodName)
                        .AppendNotSupported(errors)
                        .AppendSolveTheProblemBy()
                        .AppendSuggestImmutable(errors)
                        .AppendSuggestResizableCollection(errors)
                        .AppendSuggestDefaultCtor(errors)
                        .AppendLine($"* Use {settings.GetType().Name} and specify how copying is performed:")
                        .AppendLine($"  - {typeof(ReferenceHandling).Name}.{nameof(ReferenceHandling.Structural)} means that a the entire graph is traversed and immutable property values are copied.")
                        .AppendLine($"    - For structural Activator.CreateInstance is used to create instances so a parameterless constructor may be needed, can be private.")
                        .AppendLine($"  - {typeof(ReferenceHandling).Name}.{nameof(ReferenceHandling.References)} means that references are copied.")
                        .AppendSuggestExclude(errors);

            var message = errorBuilder.ToString();
            return message;
        }
Пример #3
0
            // ReSharper disable once UnusedParameter.Local
            private static string GetErrorText(TypeErrors errors, MemberSettings settings, string className, string methodName)
            {
                var errorBuilder = new StringBuilder();

                errorBuilder.AppendLine($"{className}.{methodName}(x, y) failed.")
                .AppendNotSupported(errors)
                .AppendSolveTheProblemBy()
                .AppendSuggestNotify(errors)
                .AppendSuggestImmutable(errors)
                .AppendSuggestResizableCollection(errors)
                .AppendSuggestDefaultCtor(errors)
                .AppendLine($"* Use {settings?.GetType().Name} and specify how change tracking is performed:")
                .AppendLine($"  - {typeof(ReferenceHandling).Name}.{nameof(ReferenceHandling.Structural)} means that a the entire graph is tracked.")
                .AppendLine($"  - {typeof(ReferenceHandling).Name}.{nameof(ReferenceHandling.References)} means that only the root level changes are tracked.")
                .AppendSuggestExclude(errors);

                var message = errorBuilder.ToString();

                return(message);
            }
Пример #4
0
        // ReSharper disable once UnusedParameter.Local
        private static string GetErrorText(this TypeErrors errors, MemberSettings settings, string className, string methodName)
        {
            var errorBuilder = new StringBuilder();

            errorBuilder.AppendCopyFailed(className, methodName)
            .AppendNotSupported(errors)
            .AppendSolveTheProblemBy()
            .AppendSuggestImmutable(errors)
            .AppendSuggestResizableCollection(errors)
            .AppendSuggestDefaultCtor(errors)
            .AppendLine($"* Use {settings.GetType().Name} and specify how copying is performed:")
            .AppendLine($"  - {typeof(ReferenceHandling).Name}.{nameof(ReferenceHandling.Structural)} means that a the entire graph is traversed and immutable property values are copied.")
            .AppendLine($"    - For structural Activator.CreateInstance is used to create instances so a parameterless constructor may be needed, can be private.")
            .AppendLine($"  - {typeof(ReferenceHandling).Name}.{nameof(ReferenceHandling.References)} means that references are copied.")
            .AppendSuggestExclude(errors);

            var message = errorBuilder.ToString();

            return(message);
        }
Пример #5
0
        private static void ThrowIfHasErrors(this TypeErrors errors, MemberSettings settings, string className, string methodName)
        {
            if (errors == null)
            {
                return;
            }

            if (errors.Errors.Count == 1 && ReferenceEquals(errors.Errors[0], RequiresReferenceHandling.ComplexType))
            {
                return;
            }

            var errorBuilder = new StringBuilder();
            errorBuilder.AppendFailed(className, methodName)
                        .AppendNotSupported(errors)
                        .AppendSolveTheProblemBy()
                        .AppendSuggestEquatable(errors)
                        .AppendLine($"* Use {settings.GetType().Name} and specify how comparing is performed:")
                        .AppendSuggestReferenceHandling(errors, settings)
                        .AppendSuggestExclude(errors);

            var message = errorBuilder.ToString();
            throw new NotSupportedException(message);
        }