public BindingCompilationRequirementsAttribute ApplySecond(BindingCompilationRequirementsAttribute attr)
 {
     return(new BindingCompilationRequirementsAttribute(
                required: Required.Concat(attr.Required).Except(attr.Excluded).Distinct().ToImmutableArray(),
                optional: Optional.Concat(attr.Optional).Distinct().ToImmutableArray(),
                excluded: Excluded.Concat(attr.Excluded).Distinct().ToImmutableArray()));
 }
Example #2
0
        protected static void InitializeBindingCore(IBinding binding, BindingCompilationRequirementsAttribute bindingRequirements)
        {
            var reporter       = binding.GetProperty <BindingErrorReporterProperty>(ErrorHandlingMode.ReturnNull);
            var throwException = reporter == null;

            reporter = reporter ?? new BindingErrorReporterProperty();
            foreach (var req in bindingRequirements.Required)
            {
                if (binding.GetProperty(req, ErrorHandlingMode.ReturnException) is Exception error)
                {
                    reporter.Errors.Push((req, error, DiagnosticSeverity.Error));
                }
            }
            if (throwException && reporter.Errors.Any())
            {
                throw new AggregateException($"Could not initialize binding '{binding.GetType()}', requirements {string.Join(", ", reporter.Errors.Select(e => e.req))} was not met",
                                             reporter.Errors.Select(e => e.error));
            }
            foreach (var req in bindingRequirements.Optional)
            {
                if (binding.GetProperty(req, ErrorHandlingMode.ReturnException) is Exception error)
                {
                    reporter.Errors.Push((req, error, DiagnosticSeverity.Info));
                }
            }
        }
Example #3
0
        protected static void InitializeBindingCore(IBinding binding, BindingCompilationRequirementsAttribute bindingRequirements)
        {
            var reporter       = binding.GetProperty <BindingErrorReporterProperty>(ErrorHandlingMode.ReturnNull);
            var throwException = reporter == null;

            reporter = reporter ?? new BindingErrorReporterProperty();
            foreach (var req in bindingRequirements.Required)
            {
                if (binding.GetProperty(req, ErrorHandlingMode.ReturnException) is Exception error)
                {
                    reporter.Errors.Push((req, error, DiagnosticSeverity.Error));
                }
            }
            if (throwException && reporter.HasErrors)
            {
                throw new AggregateException(reporter.GetErrorMessage(binding), reporter.Exceptions);
            }
        }