From 09792359364d2ea956e3a8062b5260dfad4046e3 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 12 May 2025 18:46:03 +0000 Subject: [PATCH 01/13] Use options validation source generator --- .../EgressHelper.cs | 1 - ...nostics.Monitoring.Extension.Common.csproj | 4 -- ...ileSystemEgressProviderOptionsValidator.cs | 19 +++++++ .../MetricsOptions.cs | 2 + .../MetricsOptionsValidator.cs | 12 ++++ ...soft.Diagnostics.Monitoring.Options.csproj | 2 +- .../CollectionRules/Actions/CallbackAction.cs | 29 ++++++---- .../Actions/PassThroughAction.cs | 16 +++--- .../Actions/CollectDumpAction.cs | 11 ++-- .../Actions/CollectExceptionsAction.cs | 11 ++-- .../Actions/CollectGCDumpAction.cs | 14 ++--- .../Actions/CollectLiveMetricsAction.cs | 13 ++--- .../Actions/CollectLogsAction.cs | 14 ++--- .../Actions/CollectStacksAction.cs | 14 ++--- .../Actions/CollectTraceAction.cs | 13 ++--- .../CollectionRules/Actions/ExecuteAction.cs | 14 ++--- .../Actions/GetEnvironmentVariableAction.cs | 14 ++--- .../Actions/LoadProfilerAction.cs | 14 ++--- .../Actions/SetEnvironmentVariableAction.cs | 14 ++--- .../ICollectionRuleActionDescriptor.cs | 20 +++++++ .../Actions/CollectLiveMetricsOptions.cs | 3 + .../Options/Actions/CollectTraceOptions.cs | 3 + .../Options/CollectionRuleOptions.cs | 4 ++ .../Options/CollectionRuleOptionsValidator.cs | 14 +++++ .../DataAnnotationValidateOptions.cs | 55 ------------------- .../FileSystem/FileSystemEgressExtension.cs | 2 +- .../ServiceCollectionExtensions.cs | 6 +- 27 files changed, 170 insertions(+), 168 deletions(-) create mode 100644 src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptionsValidator.cs create mode 100644 src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptionsValidator.cs create mode 100644 src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs delete mode 100644 src/Tools/dotnet-monitor/DataAnnotationValidateOptions.cs diff --git a/src/Microsoft.Diagnostics.Monitoring.Extension.Common/EgressHelper.cs b/src/Microsoft.Diagnostics.Monitoring.Extension.Common/EgressHelper.cs index 1136a5e4b3c..a00d0c0d30e 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Extension.Common/EgressHelper.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Extension.Common/EgressHelper.cs @@ -190,7 +190,6 @@ private static ServiceCollection CreateServices(ExtensionEgressPayload .Build() .Bind(options); }); - services.AddSingleton, DataAnnotationValidateOptions>(); services.AddSingleton(new EgressProperties(payload.Properties)); diff --git a/src/Microsoft.Diagnostics.Monitoring.Extension.Common/Microsoft.Diagnostics.Monitoring.Extension.Common.csproj b/src/Microsoft.Diagnostics.Monitoring.Extension.Common/Microsoft.Diagnostics.Monitoring.Extension.Common.csproj index 8879d6f8eb6..8c5c54fd3a7 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Extension.Common/Microsoft.Diagnostics.Monitoring.Extension.Common.csproj +++ b/src/Microsoft.Diagnostics.Monitoring.Extension.Common/Microsoft.Diagnostics.Monitoring.Extension.Common.csproj @@ -9,10 +9,6 @@ true - - - - diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptionsValidator.cs b/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptionsValidator.cs new file mode 100644 index 00000000000..7113f63b046 --- /dev/null +++ b/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptionsValidator.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using Microsoft.Extensions.Options; + +namespace Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem +{ + [OptionsValidator] + internal sealed partial class FileSystemEgressProviderOptionsValidator : IValidateOptions + { + IServiceProvider _serviceProvider; + + public FileSystemEgressProviderOptionsValidator(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + } +} diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs index faa647690f3..7d7b5a9e9d7 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptions.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.ComponentModel; @@ -43,6 +44,7 @@ public class MetricsOptions [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_MetricsOptions_Providers))] + [ValidateEnumeratedItems] public List Providers { get; set; } = []; [Display( diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptionsValidator.cs b/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptionsValidator.cs new file mode 100644 index 00000000000..6ec1d27f5b0 --- /dev/null +++ b/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptionsValidator.cs @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.Extensions.Options; + +namespace Microsoft.Diagnostics.Monitoring.WebApi +{ + [OptionsValidator] + public partial class MetricsOptionsValidator : IValidateOptions + { + } +} diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj b/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj index f11b2d63e0e..5212054d711 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj +++ b/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj @@ -1,4 +1,4 @@ - + 8.0.1 + + 8.0.2 8.0.15 diff --git a/eng/dependabot/net9.0/Versions.props b/eng/dependabot/net9.0/Versions.props index 074d92df8ea..1804b798cb4 100644 --- a/eng/dependabot/net9.0/Versions.props +++ b/eng/dependabot/net9.0/Versions.props @@ -9,6 +9,8 @@ 9.0.1 9.0.1 + + 9.0.4 9.0.1 diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index b75f72b30b1..fdc55fc54e4 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -126,4 +126,16 @@ + + + + + + + + diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs new file mode 100644 index 00000000000..4fad8a04472 --- /dev/null +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -0,0 +1,1268 @@ + + // + #nullable enable + #pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 + namespace Microsoft.Diagnostics.Monitoring.WebApi.Models +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __EventMetricsMeterValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsMeter options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "EventMetricsMeter.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "MeterName"; + context.DisplayName = string.IsNullOrEmpty(name) ? "EventMetricsMeter.MeterName" : $"{name}.MeterName"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MeterName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Monitoring.WebApi.Models +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __EventMetricsProviderValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsProvider options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "EventMetricsProvider.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "ProviderName"; + context.DisplayName = string.IsNullOrEmpty(name) ? "EventMetricsProvider.ProviderName" : $"{name}.ProviderName"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Monitoring.WebApi.Models +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __EventPipeProviderValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventPipeProvider options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "Name"; + context.DisplayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.Name" : $"{name}.Name"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Keywords"; + context.DisplayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.Keywords" : $"{name}.Keywords"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Keywords, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "EventLevel"; + context.DisplayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.EventLevel" : $"{name}.EventLevel"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A4); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.EventLevel, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class CollectDumpActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectDumpOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "Type"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Type" : $"{name}.Type"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A5); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Egress"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Egress" : $"{name}.Egress"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class CollectExceptionsActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectExceptionsOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "Egress"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Egress" : $"{name}.Egress"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class CollectGCDumpActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectGCDumpOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectGCDumpOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "Egress"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectGCDumpOptions.Egress" : $"{name}.Egress"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class CollectLiveMetricsActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLiveMetricsOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + if (options.Providers is not null) + { + var count = 0; + foreach (var o in options.Providers) + { + if (o is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.__EventMetricsProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); + } + else + { + (builder ??= new()).AddError(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Providers[{count}] is null" : $"{name}.Providers[{count}] is null"); + } + count++; + } + } + + if (options.Meters is not null) + { + var count = 0; + foreach (var o in options.Meters) + { + if (o is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.__EventMetricsMeterValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Meters[{count}]" : $"{name}.Meters[{count}]", o)); + } + else + { + (builder ??= new()).AddError(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Meters[{count}] is null" : $"{name}.Meters[{count}] is null"); + } + count++; + } + } + + context.MemberName = "Duration"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Duration" : $"{name}.Duration"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Egress"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Egress" : $"{name}.Egress"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class CollectLogsActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLogsOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "DefaultLevel"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.DefaultLevel" : $"{name}.DefaultLevel"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A9); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.DefaultLevel, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Duration"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Duration" : $"{name}.Duration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Egress"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Egress" : $"{name}.Egress"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Format"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Format" : $"{name}.Format"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A10); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Format, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class CollectStacksActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectStacksOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "Egress"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Egress" : $"{name}.Egress"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class CollectTraceActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectTraceOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "Profile"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Profile" : $"{name}.Profile"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A11); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Profile, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + if (options.Providers is not null) + { + var count = 0; + foreach (var o in options.Providers) + { + if (o is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.__EventPipeProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectTraceOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); + } + else + { + (builder ??= new()).AddError(string.IsNullOrEmpty(name) ? $"CollectTraceOptions.Providers[{count}] is null" : $"{name}.Providers[{count}] is null"); + } + count++; + } + } + + context.MemberName = "BufferSizeMegabytes"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.BufferSizeMegabytes" : $"{name}.BufferSizeMegabytes"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A12); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.BufferSizeMegabytes, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Duration"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Duration" : $"{name}.Duration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Egress"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Egress" : $"{name}.Egress"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + if (options.StoppingEvent is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.__TraceEventFilterValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectTraceOptions.StoppingEvent" : $"{name}.StoppingEvent", options.StoppingEvent)); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class ExecuteActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ExecuteOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "ExecuteOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Path"; + context.DisplayName = string.IsNullOrEmpty(name) ? "ExecuteOptions.Path" : $"{name}.Path"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class GetEnvironmentVariableActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.GetEnvironmentVariableOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "GetEnvironmentVariableOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Name"; + context.DisplayName = string.IsNullOrEmpty(name) ? "GetEnvironmentVariableOptions.Name" : $"{name}.Name"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class LoadProfilerActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.LoadProfilerOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "LoadProfilerOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "Path"; + context.DisplayName = string.IsNullOrEmpty(name) ? "LoadProfilerOptions.Path" : $"{name}.Path"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Clsid"; + context.DisplayName = string.IsNullOrEmpty(name) ? "LoadProfilerOptions.Clsid" : $"{name}.Clsid"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A13); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Clsid, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions +{ + partial class SetEnvironmentVariableActionDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.SetEnvironmentVariableOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "SetEnvironmentVariableOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Name"; + context.DisplayName = string.IsNullOrEmpty(name) ? "SetEnvironmentVariableOptions.Name" : $"{name}.Name"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __CollectionRuleActionOptionsValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Type"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Type" : $"{name}.Type"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __CollectionRuleLimitsOptionsValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleLimitsOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "ActionCount"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.ActionCount" : $"{name}.ActionCount"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ActionCount, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "ActionCountSlidingWindowDuration"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.ActionCountSlidingWindowDuration" : $"{name}.ActionCountSlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ActionCountSlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "RuleDuration"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.RuleDuration" : $"{name}.RuleDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A15); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RuleDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __CollectionRuleTriggerOptionsValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Type"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Type" : $"{name}.Type"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __TraceEventFilterValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.TraceEventFilter options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "TraceEventFilter.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "ProviderName"; + context.DisplayName = string.IsNullOrEmpty(name) ? "TraceEventFilter.ProviderName" : $"{name}.ProviderName"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "EventName"; + context.DisplayName = string.IsNullOrEmpty(name) ? "TraceEventFilter.EventName" : $"{name}.EventName"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.EventName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + partial class CollectionRuleOptionsValidator + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Trigger"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Trigger" : $"{name}.Trigger"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Trigger, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + if (options.Trigger is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.__CollectionRuleTriggerOptionsValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Trigger" : $"{name}.Trigger", options.Trigger)); + } + + if (options.Actions is not null) + { + var count = 0; + foreach (var o in options.Actions) + { + if (o is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.__CollectionRuleActionOptionsValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}]" : $"{name}.Actions[{count}]", o)); + } + else + { + (builder ??= new()).AddError(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}] is null" : $"{name}.Actions[{count}] is null"); + } + count++; + } + } + + if (options.Limits is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.__CollectionRuleLimitsOptionsValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Limits" : $"{name}.Limits", options.Limits)); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace __OptionValidationStaticInstances +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + file static class __Attributes + { + internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A1 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute(); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__MinLengthAttribute A2 = new __OptionValidationGeneratedAttributes.__SourceGen__MinLengthAttribute( + (int)1); + + internal static readonly global::Microsoft.Diagnostics.Monitoring.WebApi.Validation.IntegerOrHexStringAttribute A3 = new global::Microsoft.Diagnostics.Monitoring.WebApi.Validation.IntegerOrHexStringAttribute(); + + internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A4 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( + typeof(global::System.Diagnostics.Tracing.EventLevel)); + + internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A5 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( + typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.DumpType)); + + internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A6 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute() + { + ErrorMessageResourceName = "ErrorMessage_NoDefaultEgressProvider", + ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + }; + + internal static readonly global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ValidateEgressProviderAttribute A7 = new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ValidateEgressProviderAttribute(); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A8 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + typeof(global::System.TimeSpan), + "00:00:01", + "1.00:00:00"); + + internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A9 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( + typeof(global::Microsoft.Extensions.Logging.LogLevel)); + + internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A10 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( + typeof(global::Microsoft.Diagnostics.Monitoring.Options.LogFormat)); + + internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A11 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( + typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.TraceProfile)); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A12 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + (int)1, + (int)1024); + + internal static readonly global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.RequiredGuidAttribute A13 = new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.RequiredGuidAttribute(); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A14 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + (int)1, + (int)2147483647); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A15 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + typeof(global::System.TimeSpan), + "00:00:01", + "365.00:00:00"); + } +} +namespace __OptionValidationStaticInstances +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + file static class __Validators + { + } +} +namespace __OptionValidationGeneratedAttributes +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] + file class __SourceGen__MinLengthAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute + { + private static string DefaultErrorMessageString => "The field {0} must be a string or array type with a minimum length of '{1}'."; + + public __SourceGen__MinLengthAttribute(int length) : base(() => DefaultErrorMessageString) { Length = length; } + public int Length { get; } + public override bool IsValid(object? value) + { + if (Length < -1) + { + throw new global::System.InvalidOperationException("MinLengthAttribute must have a Length value that is zero or greater."); + } + if (value == null) + { + return true; + } + + int length; + if (value is string stringValue) + { + length = stringValue.Length; + } + else if (value is System.Collections.ICollection collectionValue) + { + length = collectionValue.Count; + } + else + { + throw new global::System.InvalidCastException($"The field of type {value.GetType()} must be a string, array, or ICollection type."); + } + + return length >= Length; + } + public override string FormatErrorMessage(string name) => string.Format(global::System.Globalization.CultureInfo.CurrentCulture, ErrorMessageString, name, Length); + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] + file class __SourceGen__RangeAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute + { + public __SourceGen__RangeAttribute(int minimum, int maximum) : base() + { + Minimum = minimum; + Maximum = maximum; + OperandType = typeof(int); + } + public __SourceGen__RangeAttribute(double minimum, double maximum) : base() + { + Minimum = minimum; + Maximum = maximum; + OperandType = typeof(double); + } + public __SourceGen__RangeAttribute(global::System.Type type, string minimum, string maximum) : base() + { + OperandType = type; + _needToConvertMinMax = true; + Minimum = minimum; + Maximum = maximum; + } + public object Minimum { get; private set; } + public object Maximum { get; private set; } + public bool MinimumIsExclusive { get; set; } + public bool MaximumIsExclusive { get; set; } + public global::System.Type OperandType { get; } + public bool ParseLimitsInInvariantCulture { get; set; } + public bool ConvertValueInInvariantCulture { get; set; } + public override string FormatErrorMessage(string name) => + string.Format(global::System.Globalization.CultureInfo.CurrentCulture, GetValidationErrorMessage(), name, Minimum, Maximum); + private readonly bool _needToConvertMinMax; + private volatile bool _initialized; + private readonly object _lock = new(); + private const string MinMaxError = "The minimum and maximum values must be set to valid values."; + + public override bool IsValid(object? value) + { + if (!_initialized) + { + lock (_lock) + { + if (!_initialized) + { + if (Minimum is null || Maximum is null) + { + throw new global::System.InvalidOperationException(MinMaxError); + } + if (_needToConvertMinMax) + { + System.Globalization.CultureInfo culture = ParseLimitsInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; + if (OperandType == typeof(global::System.TimeSpan)) + { + if (!global::System.TimeSpan.TryParse((string)Minimum, culture, out global::System.TimeSpan timeSpanMinimum) || + !global::System.TimeSpan.TryParse((string)Maximum, culture, out global::System.TimeSpan timeSpanMaximum)) + { + throw new global::System.InvalidOperationException(MinMaxError); + } + Minimum = timeSpanMinimum; + Maximum = timeSpanMaximum; + } + else + { + Minimum = ConvertValue(Minimum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); + Maximum = ConvertValue(Maximum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); + } + } + int cmp = ((global::System.IComparable)Minimum).CompareTo((global::System.IComparable)Maximum); + if (cmp > 0) + { + throw new global::System.InvalidOperationException("The maximum value '{Maximum}' must be greater than or equal to the minimum value '{Minimum}'."); + } + else if (cmp == 0 && (MinimumIsExclusive || MaximumIsExclusive)) + { + throw new global::System.InvalidOperationException("Cannot use exclusive bounds when the maximum value is equal to the minimum value."); + } + _initialized = true; + } + } + } + + if (value is null or string { Length: 0 }) + { + return true; + } + + System.Globalization.CultureInfo formatProvider = ConvertValueInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; + object? convertedValue; + + if (OperandType == typeof(global::System.TimeSpan)) + { + if (value is global::System.TimeSpan) + { + convertedValue = value; + } + else if (value is string) + { + if (!global::System.TimeSpan.TryParse((string)value, formatProvider, out global::System.TimeSpan timeSpanValue)) + { + return false; + } + convertedValue = timeSpanValue; + } + else + { + throw new global::System.InvalidOperationException($"A value type {value.GetType()} that is not a TimeSpan or a string has been given. This might indicate a problem with the source generator."); + } + } + else + { + try + { + convertedValue = ConvertValue(value, formatProvider); + } + catch (global::System.Exception e) when (e is global::System.FormatException or global::System.InvalidCastException or global::System.NotSupportedException) + { + return false; + } + } + + var min = (global::System.IComparable)Minimum; + var max = (global::System.IComparable)Maximum; + + return + (MinimumIsExclusive ? min.CompareTo(convertedValue) < 0 : min.CompareTo(convertedValue) <= 0) && + (MaximumIsExclusive ? max.CompareTo(convertedValue) > 0 : max.CompareTo(convertedValue) >= 0); + } + private string GetValidationErrorMessage() + { + return (MinimumIsExclusive, MaximumIsExclusive) switch + { + (false, false) => "The field {0} must be between {1} and {2}.", + (true, false) => "The field {0} must be between {1} exclusive and {2}.", + (false, true) => "The field {0} must be between {1} and {2} exclusive.", + (true, true) => "The field {0} must be between {1} exclusive and {2} exclusive.", + }; + } + private object? ConvertValue(object? value, System.Globalization.CultureInfo formatProvider) + { + if (value is string stringValue) + { + value = global::System.Convert.ChangeType(stringValue, OperandType, formatProvider); + } + else + { + value = global::System.Convert.ChangeType(value, OperandType, formatProvider); + } + return value; + } + } +} diff --git a/src/Tools/dotnet-monitor/dotnet-monitor.csproj b/src/Tools/dotnet-monitor/dotnet-monitor.csproj index 3d5349372f8..0b06625cfb1 100644 --- a/src/Tools/dotnet-monitor/dotnet-monitor.csproj +++ b/src/Tools/dotnet-monitor/dotnet-monitor.csproj @@ -11,6 +11,8 @@ enable false true + true + true @@ -19,6 +21,7 @@ + From b7b6365a8624f29a0e57ca9c043fa5a1f3c3c7a9 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 12 May 2025 20:10:54 +0000 Subject: [PATCH 03/13] Add action/trigger options validators --- .../CollectionRuleActionOptionsValidator.cs | 14 +++ .../CollectionRuleTriggerOptionsValidator.cs | 14 +++ src/Tools/dotnet-monitor/Validators.cs | 86 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs create mode 100644 src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs new file mode 100644 index 00000000000..e32800e5b71 --- /dev/null +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.Extensions.Options; + +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + [OptionsValidator] + sealed partial class CollectionRuleActionOptionsValidator : IValidateOptions + { + } +} diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs new file mode 100644 index 00000000000..9bffc825e64 --- /dev/null +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using Microsoft.Extensions.Options; + +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + [OptionsValidator] + partial class CollectionRuleTriggerOptionsValidator : IValidateOptions + { + } +} diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs index 4fad8a04472..aa04c482c12 100644 --- a/src/Tools/dotnet-monitor/Validators.cs +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -943,6 +943,49 @@ internal sealed partial class __TraceEventFilterValidator__ } } namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + partial class CollectionRuleActionOptionsValidator + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Type"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Type" : $"{name}.Type"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options { partial class CollectionRuleOptionsValidator { @@ -1012,6 +1055,49 @@ partial class CollectionRuleOptionsValidator } } } +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +{ + partial class CollectionRuleTriggerOptionsValidator + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "Type"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Type" : $"{name}.Type"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} namespace __OptionValidationStaticInstances { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] From f955e80d7742956323cdc4d9efdf91c21d06e75c Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 12 May 2025 20:35:23 +0000 Subject: [PATCH 04/13] Wire up service provider - Use generated validators for recursive validation - Pass along service provider through validation context --- .../CollectionRuleActionOptionsValidator.cs | 7 ++ .../Options/CollectionRuleOptionsValidator.cs | 7 ++ .../CollectionRuleTriggerOptionsValidator.cs | 7 ++ src/Tools/dotnet-monitor/Validators.cs | 98 +------------------ 4 files changed, 26 insertions(+), 93 deletions(-) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs index e32800e5b71..2745fbf450c 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleActionOptionsValidator.cs @@ -3,6 +3,7 @@ #nullable enable +using System; using Microsoft.Extensions.Options; namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options @@ -10,5 +11,11 @@ namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options [OptionsValidator] sealed partial class CollectionRuleActionOptionsValidator : IValidateOptions { + private readonly IServiceProvider _serviceProvider; + + public CollectionRuleActionOptionsValidator(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs index 313322e7c95..3d48b5f71d6 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs @@ -3,6 +3,7 @@ #nullable disable +using System; using Microsoft.Extensions.Options; namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options @@ -10,5 +11,11 @@ namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options [OptionsValidator] partial class CollectionRuleOptionsValidator : IValidateOptions { + private readonly IServiceProvider _serviceProvider; + + public CollectionRuleOptionsValidator(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs index 9bffc825e64..abed8482367 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleTriggerOptionsValidator.cs @@ -3,6 +3,7 @@ #nullable enable +using System; using Microsoft.Extensions.Options; namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options @@ -10,5 +11,11 @@ namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options [OptionsValidator] partial class CollectionRuleTriggerOptionsValidator : IValidateOptions { + private readonly IServiceProvider _serviceProvider; + + public CollectionRuleTriggerOptionsValidator(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } } } diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs index aa04c482c12..5a72422a248 100644 --- a/src/Tools/dotnet-monitor/Validators.cs +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -745,50 +745,6 @@ partial class SetEnvironmentVariableActionDescriptor } } namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options -{ - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - internal sealed partial class __CollectionRuleActionOptionsValidator__ - { - /// - /// Validates a specific named options instance (or all when is ). - /// - /// The name of the options instance being validated. - /// The options instance. - /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptions options) - { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER - string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); - - context.MemberName = "Type"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Type" : $"{name}.Type"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) - { - (builder ??= new()).AddResults(validationResults); - } - - context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); - - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); - } - } -} -namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __CollectionRuleLimitsOptionsValidator__ @@ -848,50 +804,6 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ } } } -namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options -{ - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - internal sealed partial class __CollectionRuleTriggerOptionsValidator__ - { - /// - /// Validates a specific named options instance (or all when is ). - /// - /// The name of the options instance being validated. - /// The options instance. - /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) - { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER - string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); - - context.MemberName = "Type"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Type" : $"{name}.Type"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) - { - (builder ??= new()).AddResults(validationResults); - } - - context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); - - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); - } - } -} namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] @@ -962,7 +874,7 @@ partial class CollectionRuleActionOptionsValidator global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -1005,7 +917,7 @@ partial class CollectionRuleOptionsValidator global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -1022,7 +934,7 @@ partial class CollectionRuleOptionsValidator if (options.Trigger is not null) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.__CollectionRuleTriggerOptionsValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Trigger" : $"{name}.Trigger", options.Trigger)); + (builder ??= new()).AddResult(new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptionsValidator(_serviceProvider).Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Trigger" : $"{name}.Trigger", options.Trigger)); } if (options.Actions is not null) @@ -1032,7 +944,7 @@ partial class CollectionRuleOptionsValidator { if (o is not null) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.__CollectionRuleActionOptionsValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}]" : $"{name}.Actions[{count}]", o)); + (builder ??= new()).AddResult(new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptionsValidator(_serviceProvider).Validate(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}]" : $"{name}.Actions[{count}]", o)); } else { @@ -1075,7 +987,7 @@ partial class CollectionRuleTriggerOptionsValidator global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif From 6801e3a59bfa43560cd139c506ad386a34ddf78b Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 14 May 2025 20:33:58 +0000 Subject: [PATCH 05/13] Add trigger validators, fix some tests --- src/Directory.Build.targets | 4 +- .../GlobalCounterOptions.cs | 28 +- ...soft.Diagnostics.Monitoring.Options.csproj | 1 + .../Validators.cs | 393 ++++++++++ .../CollectionRuleDefaultsTests.cs | 18 +- .../CollectionRuleOptionsTests.cs | 161 +++-- .../CollectionRulePipelineTests.cs | 4 +- .../FileSystemEgressExtensionTests.cs | 14 +- .../TemplatesTests.cs | 4 +- .../Actions/CollectDumpAction.cs | 7 + .../Actions/CollectExceptionsAction.cs | 7 + .../Actions/CollectGCDumpAction.cs | 7 + .../Actions/CollectLiveMetricsAction.cs | 7 + .../Actions/CollectLogsAction.cs | 7 + .../Actions/CollectStacksAction.cs | 7 + .../Actions/CollectTraceAction.cs | 7 + .../ICollectionRuleTriggerDescriptor.cs | 25 + .../Actions/CollectLogsOptions.Validate.cs | 1 + .../Actions/CollectTraceOptions.Validate.cs | 5 - .../Options/CollectionRuleOptions.Validate.cs | 15 - .../Options/CollectionRuleOptions.cs | 1 + .../Options/CollectionRuleOptionsValidator.cs | 69 +- .../Options/ValidationHelper.cs | 14 - .../AspNetRequestCountTriggerFactory.cs | 11 +- .../AspNetRequestDurationTriggerFactory.cs | 10 +- .../AspNetResponseStatusTriggerFactory.cs | 11 +- .../Triggers/EventCounterTriggerFactory.cs | 40 +- .../Triggers/EventMeterTriggerFactory.cs | 10 +- .../ServiceCollectionExtensions.cs | 9 +- src/Tools/dotnet-monitor/Validators.cs | 676 ++++++++++++++++-- 30 files changed, 1301 insertions(+), 272 deletions(-) create mode 100644 src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index fdc55fc54e4..8a8355ce625 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -131,10 +131,8 @@ - - + diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs index c360b5184d1..5c213a302be 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs @@ -7,6 +7,8 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Linq; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; namespace Microsoft.Diagnostics.Monitoring.WebApi { @@ -48,23 +50,28 @@ public class GlobalProviderOptions public float? IntervalSeconds { get; set; } } + [OptionsValidator] + partial class GlobalProviderOptionsValidator : IValidateOptions + { + } + partial class GlobalCounterOptions : IValidatableObject { public IEnumerable Validate(ValidationContext validationContext) { + var providerValidator = validationContext.GetRequiredService>(); var results = new List(); if (Providers != null) { - var providerResults = new List(); foreach ((string provider, GlobalProviderOptions options) in Providers) { - providerResults.Clear(); - if (!Validator.TryValidateObject(options, new ValidationContext(options), providerResults, true)) + ValidateOptionsResult providerResults = providerValidator.Validate(provider, options); + if (providerResults.Failed) { // We prefix the validation error with the provider. - results.AddRange(providerResults.Select(r => new ValidationResult( - string.Format(CultureInfo.CurrentCulture, OptionsDisplayStrings.ErrorMessage_NestedProviderValidationError, provider, r.ErrorMessage)))); + results.AddRange(providerResults.Failures.Select(r => new ValidationResult( + string.Format(CultureInfo.CurrentCulture, OptionsDisplayStrings.ErrorMessage_NestedProviderValidationError, provider, r)))); } } } @@ -73,6 +80,17 @@ public IEnumerable Validate(ValidationContext validationContex } } + [OptionsValidator] + partial class GlobalCounterOptionsValidator : IValidateOptions + { + private readonly IServiceProvider _serviceProvider; + + public GlobalCounterOptionsValidator(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + } + internal static class GlobalCounterOptionsExtensions { public static float GetIntervalSeconds(this GlobalCounterOptions options) => diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj b/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj index 5212054d711..b8763eb1259 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj +++ b/src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj @@ -9,6 +9,7 @@ true Library enable + true diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs new file mode 100644 index 00000000000..11b6c4bbb62 --- /dev/null +++ b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs @@ -0,0 +1,393 @@ + + // + #nullable enable + #pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 + namespace Microsoft.Diagnostics.Monitoring.WebApi +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + internal sealed partial class __MetricProviderValidator__ + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricProvider options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "MetricProvider.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "ProviderName"; + context.DisplayName = "MetricProvider.ProviderName"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Monitoring.WebApi +{ + partial class GlobalCounterOptionsValidator + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalCounterOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "GlobalCounterOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "IntervalSeconds"; + context.DisplayName = "GlobalCounterOptions.IntervalSeconds"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.IntervalSeconds, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "MaxHistograms"; + context.DisplayName = "GlobalCounterOptions.MaxHistograms"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MaxHistograms, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "MaxTimeSeries"; + context.DisplayName = "GlobalCounterOptions.MaxTimeSeries"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MaxTimeSeries, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = string.IsNullOrEmpty(name) ? "GlobalCounterOptions.Validate" : $"{name}.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Monitoring.WebApi +{ + partial class GlobalProviderOptionsValidator + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalProviderOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "GlobalProviderOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "IntervalSeconds"; + context.DisplayName = "GlobalProviderOptions.IntervalSeconds"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.IntervalSeconds, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Monitoring.WebApi +{ + partial class MetricsOptionsValidator + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricsOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "MetricsOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "MetricCount"; + context.DisplayName = "MetricsOptions.MetricCount"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MetricCount, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + if (options.Providers is not null) + { + var count = 0; + foreach (var o in options.Providers) + { + if (o is not null) + { + (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.__MetricProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"MetricsOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); + } + else + { + (builder ??= new()).AddError(string.IsNullOrEmpty(name) ? $"MetricsOptions.Providers[{count}] is null" : $"{name}.Providers[{count}] is null"); + } + count++; + } + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem +{ + partial class FileSystemEgressProviderOptionsValidator + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem.FileSystemEgressProviderOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "FileSystemEgressProviderOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "DirectoryPath"; + context.DisplayName = "FileSystemEgressProviderOptions.DirectoryPath"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.DirectoryPath, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "CopyBufferSize"; + context.DisplayName = "FileSystemEgressProviderOptions.CopyBufferSize"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.CopyBufferSize, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace __OptionValidationStaticInstances +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + file static class __Attributes + { + internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A1 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute(); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A2 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + (double)1, + (double)86400); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A3 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + (int)1, + (int)2147483647); + } +} +namespace __OptionValidationStaticInstances +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + file static class __Validators + { + } +} +namespace __OptionValidationGeneratedAttributes +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] + file class __SourceGen__RangeAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute + { + public __SourceGen__RangeAttribute(int minimum, int maximum) : base() + { + Minimum = minimum; + Maximum = maximum; + OperandType = typeof(int); + } + public __SourceGen__RangeAttribute(double minimum, double maximum) : base() + { + Minimum = minimum; + Maximum = maximum; + OperandType = typeof(double); + } + public __SourceGen__RangeAttribute(global::System.Type type, string minimum, string maximum) : base() + { + OperandType = type; + _needToConvertMinMax = true; + Minimum = minimum; + Maximum = maximum; + } + public object Minimum { get; private set; } + public object Maximum { get; private set; } + public bool MinimumIsExclusive { get; set; } + public bool MaximumIsExclusive { get; set; } + public global::System.Type OperandType { get; } + public bool ParseLimitsInInvariantCulture { get; set; } + public bool ConvertValueInInvariantCulture { get; set; } + public override string FormatErrorMessage(string name) => + string.Format(global::System.Globalization.CultureInfo.CurrentCulture, GetValidationErrorMessage(), name, Minimum, Maximum); + private readonly bool _needToConvertMinMax; + private volatile bool _initialized; + private readonly object _lock = new(); + private const string MinMaxError = "The minimum and maximum values must be set to valid values."; + + public override bool IsValid(object? value) + { + if (!_initialized) + { + lock (_lock) + { + if (!_initialized) + { + if (Minimum is null || Maximum is null) + { + throw new global::System.InvalidOperationException(MinMaxError); + } + if (_needToConvertMinMax) + { + System.Globalization.CultureInfo culture = ParseLimitsInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; + Minimum = ConvertValue(Minimum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); + Maximum = ConvertValue(Maximum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); + } + int cmp = ((global::System.IComparable)Minimum).CompareTo((global::System.IComparable)Maximum); + if (cmp > 0) + { + throw new global::System.InvalidOperationException("The maximum value '{Maximum}' must be greater than or equal to the minimum value '{Minimum}'."); + } + else if (cmp == 0 && (MinimumIsExclusive || MaximumIsExclusive)) + { + throw new global::System.InvalidOperationException("Cannot use exclusive bounds when the maximum value is equal to the minimum value."); + } + _initialized = true; + } + } + } + + if (value is null or string { Length: 0 }) + { + return true; + } + + System.Globalization.CultureInfo formatProvider = ConvertValueInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; + object? convertedValue; + + try + { + convertedValue = ConvertValue(value, formatProvider); + } + catch (global::System.Exception e) when (e is global::System.FormatException or global::System.InvalidCastException or global::System.NotSupportedException) + { + return false; + } + + var min = (global::System.IComparable)Minimum; + var max = (global::System.IComparable)Maximum; + + return + (MinimumIsExclusive ? min.CompareTo(convertedValue) < 0 : min.CompareTo(convertedValue) <= 0) && + (MaximumIsExclusive ? max.CompareTo(convertedValue) > 0 : max.CompareTo(convertedValue) >= 0); + } + private string GetValidationErrorMessage() + { + return (MinimumIsExclusive, MaximumIsExclusive) switch + { + (false, false) => "The field {0} must be between {1} and {2}.", + (true, false) => "The field {0} must be between {1} exclusive and {2}.", + (false, true) => "The field {0} must be between {1} and {2} exclusive.", + (true, true) => "The field {0} must be between {1} exclusive and {2} exclusive.", + }; + } + private object? ConvertValue(object? value, System.Globalization.CultureInfo formatProvider) + { + if (value is string stringValue) + { + value = global::System.Convert.ChangeType(stringValue, OperandType, formatProvider); + } + else + { + value = global::System.Convert.ChangeType(value, OperandType, formatProvider); + } + return value; + } + } +} diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleDefaultsTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleDefaultsTests.cs index 7ffb6ee6611..082c543a608 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleDefaultsTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleDefaultsTests.cs @@ -70,9 +70,11 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => }, host => { OptionsValidationException invalidOptionsException = Assert.Throws( - () => ActionTestsHelper.GetActionOptions(host, DefaultRuleName)); + () => ActionTestsHelper.GetActionOptions(host, DefaultRuleName)); - Assert.Equal(string.Format(OptionsDisplayStrings.ErrorMessage_NoDefaultEgressProvider), invalidOptionsException.Message); + string message = string.Format(OptionsDisplayStrings.ErrorMessage_NoDefaultEgressProvider); + + Assert.Equal($"{nameof(CollectDumpOptions.Egress)}: {message}", invalidOptionsException.Message); }); } @@ -143,7 +145,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => OptionsValidationException invalidOptionsException = Assert.Throws( () => TriggerTestsHelper.GetTriggerOptions(host, DefaultRuleName)); - VerifyRangeMessage(invalidOptionsException, nameof(AspNetRequestCountOptions.RequestCount), "1", int.MaxValue.ToString()); + VerifyRangeMessage(invalidOptionsException, nameof(AspNetRequestCountOptions), nameof(AspNetRequestCountOptions.RequestCount), "1", int.MaxValue.ToString()); }); } @@ -217,7 +219,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => OptionsValidationException invalidOptionsException = Assert.Throws( () => TriggerTestsHelper.GetTriggerOptions(host, DefaultRuleName)); - VerifyRangeMessage(invalidOptionsException, nameof(AspNetRequestDurationOptions.RequestCount), "1", int.MaxValue.ToString()); + VerifyRangeMessage(invalidOptionsException, nameof(AspNetRequestDurationOptions), nameof(AspNetRequestDurationOptions.RequestCount), "1", int.MaxValue.ToString()); }); } @@ -297,7 +299,7 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => OptionsValidationException invalidOptionsException = Assert.Throws( () => TriggerTestsHelper.GetTriggerOptions(host, DefaultRuleName)); - VerifyRangeMessage(invalidOptionsException, nameof(AspNetResponseStatusOptions.ResponseCount), "1", int.MaxValue.ToString()); + VerifyRangeMessage(invalidOptionsException, nameof(AspNetResponseStatusOptions), nameof(AspNetResponseStatusOptions.ResponseCount), "1", int.MaxValue.ToString()); }); } @@ -550,11 +552,11 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => }); } - private static void VerifyRangeMessage(Exception ex, string fieldName, string min, string max) + private static void VerifyRangeMessage(Exception ex, string typeName, string fieldName, string min, string max) { - string message = (new RangeAttribute(typeof(T), min, max)).FormatErrorMessage(fieldName); + string message = (new RangeAttribute(typeof(T), min, max)).FormatErrorMessage($"{typeName}.{fieldName}"); - Assert.Equal(message, ex.Message); + Assert.Equal($"{fieldName}: {message}", ex.Message); } } } diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleOptionsTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleOptionsTests.cs index 31cbb996d67..0621b864c40 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleOptionsTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleOptionsTests.cs @@ -77,7 +77,7 @@ public Task CollectionRuleOptions_NoTrigger() { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(CollectionRuleOptions.Trigger)); + VerifyRequiredMessage(failures, 0, nameof(CollectionRuleOptions), nameof(CollectionRuleOptions.Trigger)); }); } @@ -195,14 +195,12 @@ public Task CollectionRuleOptions_EventCounterTrigger_PropertyValidation() ex => { string[] failures = ex.Failures.ToArray(); - // Property validation failures will short-circuit the remainder of the validation - // rules, thus only observe 3 errors when one might expect 4 (the fourth being that - // either GreaterThan or LessThan should be specified). - Assert.Equal(3, failures.Length); - VerifyRequiredMessage(failures, 0, nameof(EventCounterOptions.ProviderName)); - VerifyRequiredMessage(failures, 1, nameof(EventCounterOptions.CounterName)); - VerifyRangeMessage(failures, 2, nameof(EventCounterOptions.SlidingWindowDuration), + Assert.Equal(4, failures.Length); + VerifyRequiredMessage(failures, 0, nameof(EventCounterOptions), nameof(EventCounterOptions.ProviderName)); + VerifyRequiredMessage(failures, 1, nameof(EventCounterOptions), nameof(EventCounterOptions.CounterName)); + VerifyRangeMessage(failures, 2, nameof(EventCounterOptions), nameof(EventCounterOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); + VerifyEitherRequiredMessage(failures, 3, nameof(EventCounterOptions.GreaterThan), nameof(EventCounterOptions.LessThan)); }); } @@ -362,13 +360,12 @@ public Task CollectionRuleOptions_EventMeterTrigger_PropertyValidation() ex => { string[] failures = ex.Failures.ToArray(); - // Property validation failures will short-circuit the remainder of the validation - // rules, thus only observe 3 errors when one might expect 4 (GreaterThan or LessThan should be specified). - Assert.Equal(3, failures.Length); - VerifyRequiredMessage(failures, 0, nameof(EventMeterOptions.MeterName)); - VerifyRequiredMessage(failures, 1, nameof(EventMeterOptions.InstrumentName)); - VerifyRangeMessage(failures, 2, nameof(EventMeterOptions.SlidingWindowDuration), + Assert.Equal(4, failures.Length); + VerifyRequiredMessage(failures, 0, nameof(EventMeterOptions), nameof(EventMeterOptions.MeterName)); + VerifyRequiredMessage(failures, 1, nameof(EventMeterOptions), nameof(EventMeterOptions.InstrumentName)); + VerifyRangeMessage(failures, 2, nameof(EventMeterOptions), nameof(EventMeterOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); + VerifyEitherRequiredMessage(failures, 3, nameof(EventMeterOptions.GreaterThan), nameof(EventMeterOptions.LessThan)); }); } @@ -410,8 +407,8 @@ public Task CollectionRuleOptions_EventMeterTrigger_NoInstrumentOrMeterName() { string[] failures = ex.Failures.ToArray(); Assert.Equal(2, failures.Length); - VerifyRequiredMessage(failures, 0, nameof(EventMeterOptions.MeterName)); - VerifyRequiredMessage(failures, 1, nameof(EventMeterOptions.InstrumentName)); + VerifyRequiredMessage(failures, 0, nameof(EventMeterOptions), nameof(EventMeterOptions.MeterName)); + VerifyRequiredMessage(failures, 1, nameof(EventMeterOptions), nameof(EventMeterOptions.InstrumentName)); }); } @@ -460,7 +457,7 @@ public Task CollectionRuleOptions_EventMeterTrigger_InvalidHistogramPercentile(i string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRangeMessage(failures, 0, nameof(EventMeterOptions.HistogramPercentile), + VerifyRangeMessage(failures, 0, nameof(EventMeterOptions), nameof(EventMeterOptions.HistogramPercentile), TriggerOptionsConstants.Percentage_MinValue.ToString(), TriggerOptionsConstants.Percentage_MaxValue.ToString()); }); } @@ -550,11 +547,11 @@ public Task CollectionRuleOptions_CPUUsageTrigger_PropertyValidation() string[] failures = ex.Failures.ToArray(); Assert.Equal(3, failures.Length); - VerifyRangeMessage(failures, 0, nameof(CPUUsageOptions.GreaterThan), + VerifyRangeMessage(failures, 0, nameof(CPUUsageOptions), nameof(CPUUsageOptions.GreaterThan), TriggerOptionsConstants.Percentage_MinValue.ToString(), TriggerOptionsConstants.Percentage_MaxValue.ToString()); - VerifyRangeMessage(failures, 1, nameof(CPUUsageOptions.LessThan), + VerifyRangeMessage(failures, 1, nameof(CPUUsageOptions), nameof(CPUUsageOptions.LessThan), TriggerOptionsConstants.Percentage_MinValue.ToString(), TriggerOptionsConstants.Percentage_MaxValue.ToString()); - VerifyRangeMessage(failures, 2, nameof(CPUUsageOptions.SlidingWindowDuration), + VerifyRangeMessage(failures, 2, nameof(CPUUsageOptions), nameof(CPUUsageOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); }); } @@ -578,11 +575,11 @@ public Task CollectionRuleOptions_GCHeapSizeTrigger_PropertyValidation() string[] failures = ex.Failures.ToArray(); Assert.Equal(3, failures.Length); - VerifyRangeMessage(failures, 0, nameof(GCHeapSizeOptions.GreaterThan), + VerifyRangeMessage(failures, 0, nameof(GCHeapSizeOptions), nameof(GCHeapSizeOptions.GreaterThan), "0", double.MaxValue.ToString()); - VerifyRangeMessage(failures, 1, nameof(GCHeapSizeOptions.LessThan), + VerifyRangeMessage(failures, 1, nameof(GCHeapSizeOptions), nameof(GCHeapSizeOptions.LessThan), "0", double.MaxValue.ToString()); - VerifyRangeMessage(failures, 2, nameof(GCHeapSizeOptions.SlidingWindowDuration), + VerifyRangeMessage(failures, 2, nameof(GCHeapSizeOptions), nameof(GCHeapSizeOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); }); } @@ -606,11 +603,11 @@ public Task CollectionRuleOptions_ThreadpoolQueueLengthTrigger_PropertyValidatio string[] failures = ex.Failures.ToArray(); Assert.Equal(3, failures.Length); - VerifyRangeMessage(failures, 0, nameof(ThreadpoolQueueLengthOptions.GreaterThan), + VerifyRangeMessage(failures, 0, nameof(ThreadpoolQueueLengthOptions), nameof(ThreadpoolQueueLengthOptions.GreaterThan), "0", double.MaxValue.ToString()); - VerifyRangeMessage(failures, 1, nameof(ThreadpoolQueueLengthOptions.LessThan), + VerifyRangeMessage(failures, 1, nameof(ThreadpoolQueueLengthOptions), nameof(ThreadpoolQueueLengthOptions.LessThan), "0", double.MaxValue.ToString()); - VerifyRangeMessage(failures, 2, nameof(ThreadpoolQueueLengthOptions.SlidingWindowDuration), + VerifyRangeMessage(failures, 2, nameof(ThreadpoolQueueLengthOptions), nameof(ThreadpoolQueueLengthOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); }); } @@ -703,7 +700,7 @@ public Task CollectionRuleOptions_AspNetRequestCountTrigger_RequiredPropertyVali string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRangeMessage(failures, 0, nameof(AspNetRequestCountOptions.RequestCount), "1", int.MaxValue.ToString()); // Since non-nullable, defaults to 0 + VerifyRangeMessage(failures, 0, nameof(AspNetRequestCountOptions), nameof(AspNetRequestCountOptions.RequestCount), "1", int.MaxValue.ToString()); // Since non-nullable, defaults to 0 }); } @@ -725,8 +722,8 @@ public Task CollectionRuleOptions_AspNetRequestCountTrigger_RangePropertyValidat string[] failures = ex.Failures.ToArray(); Assert.Equal(2, failures.Length); - VerifyRangeMessage(failures, 0, nameof(AspNetRequestCountOptions.RequestCount), "1", int.MaxValue.ToString()); - VerifyRangeMessage(failures, 1, nameof(AspNetRequestCountOptions.SlidingWindowDuration), + VerifyRangeMessage(failures, 0, nameof(AspNetRequestCountOptions), nameof(AspNetRequestCountOptions.RequestCount), "1", int.MaxValue.ToString()); + VerifyRangeMessage(failures, 1, nameof(AspNetRequestCountOptions), nameof(AspNetRequestCountOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); }); } @@ -799,7 +796,7 @@ public Task CollectionRuleOptions_AspNetRequestDurationTrigger_RequiredPropertyV string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRangeMessage(failures, 0, nameof(AspNetRequestDurationOptions.RequestCount), "1", int.MaxValue.ToString()); // Since non-nullable, defaults to 0 + VerifyRangeMessage(failures, 0, nameof(AspNetRequestDurationOptions), nameof(AspNetRequestDurationOptions.RequestCount), "1", int.MaxValue.ToString()); // Since non-nullable, defaults to 0 }); } @@ -822,10 +819,10 @@ public Task CollectionRuleOptions_AspNetRequestDurationTrigger_RangePropertyVali string[] failures = ex.Failures.ToArray(); Assert.Equal(3, failures.Length); - VerifyRangeMessage(failures, 0, nameof(AspNetRequestDurationOptions.RequestCount), "1", int.MaxValue.ToString()); - VerifyRangeMessage(failures, 1, nameof(AspNetRequestDurationOptions.RequestDuration), + VerifyRangeMessage(failures, 0, nameof(AspNetRequestDurationOptions), nameof(AspNetRequestDurationOptions.RequestCount), "1", int.MaxValue.ToString()); + VerifyRangeMessage(failures, 1, nameof(AspNetRequestDurationOptions), nameof(AspNetRequestDurationOptions.RequestDuration), AspNetRequestDurationOptions.RequestDuration_MinValue, AspNetRequestDurationOptions.RequestDuration_MaxValue); - VerifyRangeMessage(failures, 2, nameof(AspNetRequestDurationOptions.SlidingWindowDuration), + VerifyRangeMessage(failures, 2, nameof(AspNetRequestDurationOptions), nameof(AspNetRequestDurationOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); }); } @@ -901,8 +898,8 @@ public Task CollectionRuleOptions_AspNetResponseStatusTrigger_RequiredPropertyVa string[] failures = ex.Failures.ToArray(); Assert.Equal(2, failures.Length); - VerifyRequiredMessage(failures, 0, nameof(AspNetResponseStatusOptions.StatusCodes)); - VerifyRangeMessage(failures, 1, nameof(AspNetResponseStatusOptions.ResponseCount), "1", int.MaxValue.ToString()); // Since non-nullable, defaults to 0 + VerifyRequiredMessage(failures, 0, nameof(AspNetResponseStatusOptions), nameof(AspNetResponseStatusOptions.StatusCodes)); + VerifyRangeMessage(failures, 1, nameof(AspNetResponseStatusOptions), nameof(AspNetResponseStatusOptions.ResponseCount), "1", int.MaxValue.ToString()); // Since non-nullable, defaults to 0 }); } @@ -927,9 +924,9 @@ public Task CollectionRuleOptions_AspNetResponseStatusTrigger_RangePropertyValid string[] failures = ex.Failures.ToArray(); Assert.Equal(3, failures.Length); - VerifyStatusCodesRegexMessage(failures, 0, nameof(AspNetResponseStatusOptions.StatusCodes)); - VerifyRangeMessage(failures, 1, nameof(AspNetResponseStatusOptions.ResponseCount), "1", int.MaxValue.ToString()); - VerifyRangeMessage(failures, 2, nameof(AspNetResponseStatusOptions.SlidingWindowDuration), + VerifyStatusCodesRegexMessage(failures, 0, nameof(AspNetResponseStatusOptions), nameof(AspNetResponseStatusOptions.StatusCodes)); + VerifyRangeMessage(failures, 1, nameof(AspNetResponseStatusOptions), nameof(AspNetResponseStatusOptions.ResponseCount), "1", int.MaxValue.ToString()); + VerifyRangeMessage(failures, 2, nameof(AspNetResponseStatusOptions), nameof(AspNetResponseStatusOptions.SlidingWindowDuration), TriggerOptionsConstants.SlidingWindowDuration_MinValue, TriggerOptionsConstants.SlidingWindowDuration_MaxValue); }); } @@ -968,7 +965,7 @@ public Task CollectionRuleOptions_CollectDumpAction_PropertyValidation() { string[] failures = ex.Failures.ToArray(); Assert.Equal(2, failures.Length); - VerifyEnumDataTypeMessage(failures, 0, nameof(CollectDumpOptions.Type)); + VerifyEnumDataTypeMessage(failures, 0, nameof(CollectDumpOptions), nameof(CollectDumpOptions.Type)); VerifyEgressNotExistMessage(failures, 1, UnknownEgressName); }); } @@ -1091,10 +1088,10 @@ public Task CollectionRuleOptions_CollectLogsAction_PropertyValidation() { string[] failures = ex.Failures.ToArray(); Assert.Equal(3, failures.Length); - VerifyEnumDataTypeMessage(failures, 0, nameof(CollectLogsOptions.DefaultLevel)); - VerifyRangeMessage(failures, 1, nameof(CollectLogsOptions.Duration), + VerifyEnumDataTypeMessage(failures, 0, nameof(CollectLogsOptions), nameof(CollectLogsOptions.DefaultLevel)); + VerifyRangeMessage(failures, 1, nameof(CollectLogsOptions), nameof(CollectLogsOptions.Duration), ActionOptionsConstants.Duration_MinValue, ActionOptionsConstants.Duration_MaxValue); - VerifyRequiredOrDefaultEgressProvider(failures, 2); + VerifyRequiredOrDefaultEgressProvider(failures, 2, nameof(CollectLogsOptions.Egress)); }); } @@ -1122,7 +1119,7 @@ public Task CollectionRuleOptions_CollectLogsAction_FilterSpecValidation() { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyEnumDataTypeMessage(failures, 0, nameof(CollectLogsOptions.FilterSpecs)); + VerifyEnumDataTypeMessage(failures, 0, nameof(CollectLogsOptions), nameof(CollectLogsOptions.FilterSpecs)); }); } @@ -1259,12 +1256,12 @@ public Task CollectionRuleOptions_CollectTraceAction_PropertyValidation() { string[] failures = ex.Failures.ToArray(); Assert.Equal(4, failures.Length); - VerifyEnumDataTypeMessage(failures, 0, nameof(CollectTraceOptions.Profile)); - VerifyRangeMessage(failures, 1, nameof(CollectTraceOptions.BufferSizeMegabytes), + VerifyEnumDataTypeMessage(failures, 0, nameof(CollectTraceOptions), nameof(CollectTraceOptions.Profile)); + VerifyRangeMessage(failures, 1, nameof(CollectTraceOptions), nameof(CollectTraceOptions.BufferSizeMegabytes), ActionOptionsConstants.BufferSizeMegabytes_MinValue_String, ActionOptionsConstants.BufferSizeMegabytes_MaxValue_String); - VerifyRangeMessage(failures, 2, nameof(CollectTraceOptions.Duration), + VerifyRangeMessage(failures, 2, nameof(CollectTraceOptions), nameof(CollectTraceOptions.Duration), ActionOptionsConstants.Duration_MinValue, ActionOptionsConstants.Duration_MaxValue); - VerifyRequiredOrDefaultEgressProvider(failures, 3); + VerifyRequiredOrDefaultEgressProvider(failures, 3, nameof(CollectTraceOptions.Egress)); }); } @@ -1294,7 +1291,7 @@ public Task CollectionRuleOptions_CollectTraceAction_ValidateProviderIntervals() ex => { string failure = Assert.Single(ex.Failures); - VerifyProviderIntervalMessage(failure, MonitoringSourceConfiguration.SystemRuntimeEventSourceName, ExpectedInterval); + VerifyProviderIntervalMessage(failure, nameof(EventPipeProvider.Arguments), MonitoringSourceConfiguration.SystemRuntimeEventSourceName, ExpectedInterval); }); } @@ -1401,7 +1398,7 @@ public Task CollectionRuleOptions_CollectTraceAction_ProviderPropertyValidation( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(EventPipeProvider.Name)); + VerifyRequiredMessage(failures, 0, nameof(EventPipeProvider), nameof(EventPipeProvider.Name)); }); } @@ -1586,7 +1583,7 @@ public Task CollectionRuleOptions_CollectLiveMetricsAction_PropertyValidation() { string[] failures = ex.Failures.ToArray(); Assert.Equal(2, failures.Length); - VerifyRangeMessage(failures, 0, nameof(CollectTraceOptions.Duration), + VerifyRangeMessage(failures, 0, nameof(CollectLiveMetricsOptions), nameof(CollectLiveMetricsOptions.Duration), ActionOptionsConstants.Duration_MinValue, ActionOptionsConstants.Duration_MaxValue); VerifyEgressNotExistMessage(failures, 1, UnknownEgressName); }); @@ -1645,7 +1642,7 @@ public Task CollectionRuleOptions_ExecuteAction_PropertyValidation() { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(ExecuteOptions.Path)); + VerifyRequiredMessage(failures, 0, nameof(ExecuteOptions), nameof(ExecuteOptions.Path)); }); } @@ -1694,7 +1691,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(LoadProfilerOptions.Path)); + VerifyRequiredMessage(failures, 0, nameof(LoadProfilerOptions), nameof(LoadProfilerOptions.Path)); }); await ValidateFailure( @@ -1713,7 +1710,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(LoadProfilerOptions.Path)); + VerifyRequiredMessage(failures, 0, nameof(LoadProfilerOptions), nameof(LoadProfilerOptions.Path)); }); await ValidateFailure( @@ -1732,7 +1729,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(LoadProfilerOptions.Path)); + VerifyRequiredMessage(failures, 0, nameof(LoadProfilerOptions), nameof(LoadProfilerOptions.Path)); }); } @@ -1756,7 +1753,7 @@ public Task CollectionRuleOptions_LoadProfilerAction_ClsidPropertyValidation() { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredGuidMessage(failures, 0, nameof(LoadProfilerOptions.Clsid)); + VerifyRequiredGuidMessage(failures, 0, nameof(LoadProfilerOptions), nameof(LoadProfilerOptions.Clsid)); }); } @@ -1813,7 +1810,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(SetEnvironmentVariableOptions.Name)); + VerifyRequiredMessage(failures, 0, nameof(SetEnvironmentVariableOptions), nameof(SetEnvironmentVariableOptions.Name)); }); await ValidateFailure( @@ -1827,7 +1824,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(SetEnvironmentVariableOptions.Name)); + VerifyRequiredMessage(failures, 0, nameof(SetEnvironmentVariableOptions), nameof(SetEnvironmentVariableOptions.Name)); }); await ValidateFailure( @@ -1841,7 +1838,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(SetEnvironmentVariableOptions.Name)); + VerifyRequiredMessage(failures, 0, nameof(SetEnvironmentVariableOptions), nameof(SetEnvironmentVariableOptions.Name)); }); } @@ -1878,7 +1875,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(GetEnvironmentVariableOptions.Name)); + VerifyRequiredMessage(failures, 0, nameof(GetEnvironmentVariableOptions), nameof(GetEnvironmentVariableOptions.Name)); }); await ValidateFailure( @@ -1892,7 +1889,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(GetEnvironmentVariableOptions.Name)); + VerifyRequiredMessage(failures, 0, nameof(GetEnvironmentVariableOptions), nameof(GetEnvironmentVariableOptions.Name)); }); await ValidateFailure( @@ -1906,7 +1903,7 @@ await ValidateFailure( { string[] failures = ex.Failures.ToArray(); Assert.Single(failures); - VerifyRequiredMessage(failures, 0, nameof(GetEnvironmentVariableOptions.Name)); + VerifyRequiredMessage(failures, 0, nameof(GetEnvironmentVariableOptions), nameof(GetEnvironmentVariableOptions.Name)); }); } @@ -2261,37 +2258,39 @@ private static void VerifyUnknownTriggerTypeMessage(string[] failures, int index Assert.Equal(message, failures[index]); } - private static void VerifyRequiredMessage(string[] failures, int index, string fieldName) + private static void VerifyRequiredMessage(string[] failures, int index, string typeName, string fieldName) { - string message = (new RequiredAttribute()).FormatErrorMessage(fieldName); + string message = (new RequiredAttribute()).FormatErrorMessage($"{typeName}.{fieldName}"); - Assert.Equal(message, failures[index]); + Assert.Equal($"{fieldName}: {message}", failures[index]); } - private static void VerifyRequiredOrDefaultEgressProvider(string[] failures, int index) + private static void VerifyRequiredOrDefaultEgressProvider(string[] failures, int index, string fieldName) { - Assert.Equal(WebApi.OptionsDisplayStrings.ErrorMessage_NoDefaultEgressProvider, failures[index]); + string message = WebApi.OptionsDisplayStrings.ErrorMessage_NoDefaultEgressProvider; + + Assert.Equal($"{fieldName}: {message}", failures[index]); } - private static void VerifyRequiredGuidMessage(string[] failures, int index, string fieldName) + private static void VerifyRequiredGuidMessage(string[] failures, int index, string typeName, string fieldName) { - string message = (new RequiredGuidAttribute()).FormatErrorMessage(fieldName); + string message = (new RequiredGuidAttribute()).FormatErrorMessage($"{typeName}.{fieldName}"); Assert.Equal(message, failures[index]); } - private static void VerifyEnumDataTypeMessage(string[] failures, int index, string fieldName) + private static void VerifyEnumDataTypeMessage(string[] failures, int index, string typeName, string fieldName) { - string message = (new EnumDataTypeAttribute(typeof(T))).FormatErrorMessage(fieldName); + string message = (new EnumDataTypeAttribute(typeof(T))).FormatErrorMessage($"{typeName}.{fieldName}"); - Assert.Equal(message, failures[index]); + Assert.Equal($"{fieldName}: {message}", failures[index]); } - private static void VerifyRangeMessage(string[] failures, int index, string fieldName, string min, string max) + private static void VerifyRangeMessage(string[] failures, int index, string typeName, string fieldName, string min, string max) { - string message = (new RangeAttribute(typeof(T), min, max)).FormatErrorMessage(fieldName); + string message = (new RangeAttribute(typeof(T), min, max)).FormatErrorMessage($"{typeName}.{fieldName}"); - Assert.Equal(message, failures[index]); + Assert.Equal($"{fieldName}: {message}", failures[index]); } private static void VerifyEitherRequiredMessage(string[] failures, int index, string fieldName1, string fieldName2) @@ -2305,14 +2304,14 @@ private static void VerifyEitherRequiredMessage(string[] failures, int index, st Assert.Equal(message, failures[index]); } - private static void VerifyStatusCodesRegexMessage(string[] failures, int index, string fieldName) + private static void VerifyStatusCodesRegexMessage(string[] failures, int index, string typeName, string fieldName) { string message = string.Format( CultureInfo.InvariantCulture, WebApi.OptionsDisplayStrings.ErrorMessage_StatusCodesRegularExpressionDoesNotMatch, - fieldName); + $"{typeName}.{fieldName}"); - Assert.Equal(message, failures[index]); + Assert.Equal($"{fieldName}: {message}", failures[index]); } private static void VerifyBothCannotBeSpecifiedMessage(string[] failures, int index, string fieldName1, string fieldName2) @@ -2369,11 +2368,11 @@ private static void VerifyMissingStoppingEventProviderMessage(string[] failures, Assert.Equal(message, failures[index]); } - private static void VerifyProviderIntervalMessage(string failure, string provider, int expectedInterval) + private static void VerifyProviderIntervalMessage(string failure, string fieldName, string provider, int expectedInterval) { string message = string.Format(CultureInfo.CurrentCulture, WebApi.Strings.ErrorMessage_InvalidMetricInterval, provider, expectedInterval); - Assert.Equal(message, failure); + Assert.Equal($"{fieldName}: {message}", failure); } private static void VerifyNestedGlobalInterval(string failure, string provider) @@ -2381,9 +2380,9 @@ private static void VerifyNestedGlobalInterval(string failure, string provider) string rangeValidationMessage = typeof(WebApi.GlobalProviderOptions) .GetProperty(nameof(WebApi.GlobalProviderOptions.IntervalSeconds)) .GetCustomAttribute() - .FormatErrorMessage(nameof(WebApi.GlobalProviderOptions.IntervalSeconds)); + .FormatErrorMessage($"{nameof(WebApi.GlobalProviderOptions)}.{nameof(WebApi.GlobalProviderOptions.IntervalSeconds)}"); - string message = string.Format(CultureInfo.CurrentCulture, WebApi.OptionsDisplayStrings.ErrorMessage_NestedProviderValidationError, provider, rangeValidationMessage); + string message = string.Format(CultureInfo.CurrentCulture, WebApi.OptionsDisplayStrings.ErrorMessage_NestedProviderValidationError, provider, $"{nameof(WebApi.GlobalProviderOptions.IntervalSeconds)}: {rangeValidationMessage}"); Assert.Equal(message, failure); } } diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRulePipelineTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRulePipelineTests.cs index 75ca11aca3d..a3889d34d03 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRulePipelineTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRulePipelineTests.cs @@ -473,8 +473,8 @@ public Task CollectionRulePipeline_ActionCountLimitSlidingDurationTest(TargetFra { const int IterationCount = 5; const int ExpectedActionExecutionCount = 3; - TimeSpan SlidingWindowDuration = TimeSpan.FromMilliseconds(100); - TimeSpan ClockIncrementDuration = TimeSpan.FromMilliseconds(10); + TimeSpan SlidingWindowDuration = TimeSpan.FromMilliseconds(1000); + TimeSpan ClockIncrementDuration = TimeSpan.FromMilliseconds(100); MockTimeProvider timeProvider = new(); ManualTriggerService triggerService = new(); diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/FileSystemEgressExtensionTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/FileSystemEgressExtensionTests.cs index 9a9ba33bf8b..4e12d708f58 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/FileSystemEgressExtensionTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/FileSystemEgressExtensionTests.cs @@ -30,6 +30,7 @@ public sealed class FileSystemEgressExtensionTests const string ExpectedFileContent = "This is egressed data."; private static readonly string CopyBufferSize_RangeErrorMessage = CreateRangeMessage( + nameof(FileSystemEgressProviderOptions), nameof(FileSystemEgressProviderOptions.CopyBufferSize), FileSystemEgressProviderOptions.CopyBufferSize_MinValue.ToString(), FileSystemEgressProviderOptions.CopyBufferSize_MaxValue.ToString()); @@ -51,7 +52,8 @@ public async Task FileSystemEgressExtension_EmptyConfiguration_ThrowsException() OptionsValidationException exception = await Assert.ThrowsAsync( () => extension.EgressArtifact(ProviderName, CreateSettings(), WriteFileContent, CancellationToken.None)); string errorMessage = Assert.Single(exception.Failures); - Assert.Equal(CreateRequiredMessage(nameof(FileSystemEgressProviderOptions.DirectoryPath)), errorMessage); + string message = CreateRequiredMessage(nameof(FileSystemEgressProviderOptions), nameof(FileSystemEgressProviderOptions.DirectoryPath)); + Assert.Equal($"{nameof(FileSystemEgressProviderOptions.DirectoryPath)}: {message}", errorMessage); } [Fact] @@ -70,7 +72,7 @@ public async Task FileSystemEgressExtension_CopyBufferSizeZero_ThrowsException() OptionsValidationException exception = await Assert.ThrowsAsync( () => extension.EgressArtifact(ProviderName, CreateSettings(), WriteFileContent, CancellationToken.None)); string errorMessage = Assert.Single(exception.Failures); - Assert.Equal(CopyBufferSize_RangeErrorMessage, errorMessage); + Assert.Equal($"{nameof(FileSystemEgressProviderOptions.CopyBufferSize)}: {CopyBufferSize_RangeErrorMessage}", errorMessage); } [Fact] @@ -175,14 +177,14 @@ private static EgressArtifactSettings CreateSettings() }; } - private static string CreateRangeMessage(string fieldName, string min, string max) + private static string CreateRangeMessage(string typeName, string fieldName, string min, string max) { - return (new RangeAttribute(typeof(T), min, max)).FormatErrorMessage(fieldName); + return (new RangeAttribute(typeof(T), min, max)).FormatErrorMessage($"{typeName}.{fieldName}"); } - private static string CreateRequiredMessage(string fieldName) + private static string CreateRequiredMessage(string typeName, string fieldName) { - return (new RequiredAttribute()).FormatErrorMessage(fieldName); + return (new RequiredAttribute()).FormatErrorMessage($"{typeName}.{fieldName}"); } private static async Task WriteFileContent(Stream stream, CancellationToken token) diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/TemplatesTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/TemplatesTests.cs index 307bedde981..182df0c8329 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/TemplatesTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/TemplatesTests.cs @@ -98,8 +98,8 @@ await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => { } string[] failures = ex.Failures.ToArray(); Assert.Equal(2, failures.Length); - Assert.Equal(string.Format(TemplateNotFoundErrorMessage, "TriggerTemplateINVALID"), failures[0]); - Assert.Equal(string.Format(TemplateNotFoundErrorMessage, "FilterTemplateINVALID"), failures[1]); + Assert.Equal(string.Format($"{nameof(CollectionRuleOptions.Trigger)}: {TemplateNotFoundErrorMessage}", "TriggerTemplateINVALID"), failures[0]); + Assert.Equal(string.Format($"{nameof(CollectionRuleOptions.Filters)}: {TemplateNotFoundErrorMessage}", "FilterTemplateINVALID"), failures[1]); }, overrideSource: GetConfigurationSources()); } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectDumpAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectDumpAction.cs index 79a3f5a2cea..47bb2333b72 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectDumpAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectDumpAction.cs @@ -74,6 +74,13 @@ protected override EgressOperation CreateArtifactOperation(CollectionRuleMetadat [OptionsValidator] internal sealed partial class CollectDumpActionDescriptor : ICollectionRuleActionDescriptor { + private readonly IServiceProvider _serviceProvider; + + public CollectDumpActionDescriptor(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public string ActionName => KnownCollectionRuleActions.CollectDump; public void BindOptions(IConfigurationSection settingsSection, out CollectDumpOptions options) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectExceptionsAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectExceptionsAction.cs index e2d8a26f4fc..ec0c27821a7 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectExceptionsAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectExceptionsAction.cs @@ -63,6 +63,13 @@ protected override EgressOperation CreateArtifactOperation(CollectionRuleMetadat [OptionsValidator] internal sealed partial class CollectExceptionsActionDescriptor : ICollectionRuleActionDescriptor { + private readonly IServiceProvider _serviceProvider; + + public CollectExceptionsActionDescriptor(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public string ActionName => KnownCollectionRuleActions.CollectExceptions; public void BindOptions(IConfigurationSection settingsSection, out CollectExceptionsOptions options) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs index b19330222bd..c4c327cccdf 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs @@ -66,6 +66,13 @@ protected override EgressOperation CreateArtifactOperation(CollectionRuleMetadat [OptionsValidator] internal sealed partial class CollectGCDumpActionDescriptor : ICollectionRuleActionDescriptor { + private readonly IServiceProvider _serviceProvider; + + public CollectGCDumpActionDescriptor(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public string ActionName => KnownCollectionRuleActions.CollectGCDump; public void BindOptions(IConfigurationSection settingsSection, out CollectGCDumpOptions options) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs index bcbfdcd6507..4a769f1f380 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs @@ -101,6 +101,13 @@ protected override EgressOperation CreateArtifactOperation(CollectionRuleMetadat [OptionsValidator] internal sealed partial class CollectLiveMetricsActionDescriptor : ICollectionRuleActionDescriptor { + private readonly IServiceProvider _serviceProvider; + + public CollectLiveMetricsActionDescriptor(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public string ActionName => KnownCollectionRuleActions.CollectLiveMetrics; public void BindOptions(IConfigurationSection settingsSection, out CollectLiveMetricsOptions options) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs index 94a36450493..979df57b384 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs @@ -90,6 +90,13 @@ protected override EgressOperation CreateArtifactOperation(CollectionRuleMetadat [OptionsValidator] internal sealed partial class CollectLogsActionDescriptor : ICollectionRuleActionDescriptor { + private readonly IServiceProvider _serviceProvider; + + public CollectLogsActionDescriptor(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public string ActionName => KnownCollectionRuleActions.CollectLogs; public void BindOptions(IConfigurationSection settingsSection, out CollectLogsOptions options) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs index 89c2b3b19cf..61a4ea22eeb 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs @@ -78,6 +78,13 @@ private static StackFormat MapCallStackFormat(CallStackFormat format) => [OptionsValidator] internal sealed partial class CollectStacksActionDescriptor : ICollectionRuleActionDescriptor { + private readonly IServiceProvider _serviceProvider; + + public CollectStacksActionDescriptor(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public string ActionName => KnownCollectionRuleActions.CollectStacks; public void BindOptions(IConfigurationSection settingsSection, out CollectStacksOptions options) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs index b0b232d964c..df46850e0bc 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs @@ -113,6 +113,13 @@ protected override EgressOperation CreateArtifactOperation(CollectionRuleMetadat [OptionsValidator] internal sealed partial class CollectTraceActionDescriptor : ICollectionRuleActionDescriptor { + private readonly IServiceProvider _serviceProvider; + + public CollectTraceActionDescriptor(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public string ActionName => KnownCollectionRuleActions.CollectTrace; public void BindOptions(IConfigurationSection settingsSection, out CollectTraceOptions options) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Configuration/ICollectionRuleTriggerDescriptor.cs b/src/Tools/dotnet-monitor/CollectionRules/Configuration/ICollectionRuleTriggerDescriptor.cs index aa167eddc2a..b0e5c281868 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Configuration/ICollectionRuleTriggerDescriptor.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Configuration/ICollectionRuleTriggerDescriptor.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers; using System; namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration @@ -16,4 +18,27 @@ interface ICollectionRuleTriggerDescriptor bool TryBindOptions(IConfigurationSection settingsSection, out object? settings); } + + internal interface ICollectionRuleTriggerDescriptor + : IValidateOptions, ICollectionRuleTriggerDescriptor + where TOptions : class + where TFactory : ICollectionRuleTriggerFactory + { + Type ICollectionRuleTriggerDescriptor.OptionsType => typeof(TOptions); + + Type ICollectionRuleTriggerDescriptor.FactoryType => typeof(TFactory); + + bool TryBindOptions(IConfigurationSection settingsSection, out TOptions settings); + + bool ICollectionRuleTriggerDescriptor.TryBindOptions(IConfigurationSection settingsSection, out object? settings) + { + if (TryBindOptions(settingsSection, out TOptions typedSettings)) + { + settings = typedSettings; + return true; + } + settings = null; + return false; + } + } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectLogsOptions.Validate.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectLogsOptions.Validate.cs index e8ede3ded8c..d63fbc60438 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectLogsOptions.Validate.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectLogsOptions.Validate.cs @@ -25,6 +25,7 @@ IEnumerable IValidatableObject.Validate(ValidationContext vali ValidationContext filterSpecsContext = new(FilterSpecs, validationContext, validationContext.Items); filterSpecsContext.MemberName = nameof(FilterSpecs); + filterSpecsContext.DisplayName = $"{nameof(CollectLogsOptions)}.{nameof(FilterSpecs)}"; // Validate that the category is not null and that the level is a valid level value. foreach ((string category, LogLevel? level) in FilterSpecs) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectTraceOptions.Validate.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectTraceOptions.Validate.cs index 6874ec2354b..fa60ac0d19b 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectTraceOptions.Validate.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectTraceOptions.Validate.cs @@ -87,11 +87,6 @@ IEnumerable IValidatableObject.Validate(ValidationContext vali int index = 0; foreach (EventPipeProvider provider in Providers) { - ValidationContext providerContext = new(provider, validationContext, validationContext.Items); - providerContext.MemberName = nameof(Providers) + "[" + index.ToString(CultureInfo.InvariantCulture) + "]"; - - Validator.TryValidateObject(provider, providerContext, results, validateAllProperties: true); - if (counterOptions != null && !CounterValidator.ValidateProvider(counterOptions, provider, out string? errorMessage)) { results.Add(new ValidationResult(errorMessage, new[] { nameof(EventPipeProvider.Arguments) })); diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.Validate.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.Validate.cs index 2af986cc1a8..de76f082bcf 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.Validate.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.Validate.cs @@ -27,21 +27,6 @@ IEnumerable IValidatableObject.Validate(ValidationContext vali return results; } - ValidationContext filtersContext = new(Filters, validationContext, validationContext.Items); - filtersContext.MemberName = nameof(Filters); - ValidationHelper.TryValidateItems(Filters, filtersContext, results); - - if (null != Trigger) - { - ValidationContext triggerContext = new(Trigger, validationContext, validationContext.Items); - triggerContext.MemberName = nameof(Trigger); - Validator.TryValidateObject(Trigger, triggerContext, results); - } - - ValidationContext actionsContext = new(Actions, validationContext, validationContext.Items); - actionsContext.MemberName = nameof(Actions); - ValidationHelper.TryValidateItems(Actions, actionsContext, results); - var actionNames = new HashSet(StringComparer.Ordinal); foreach (CollectionRuleActionOptions option in Actions) { diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.cs index fc1915d42b8..461cfda4c1b 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.cs @@ -18,6 +18,7 @@ internal sealed partial class CollectionRuleOptions [Display( ResourceType = typeof(OptionsDisplayStrings), Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectionRuleOptions_Filters))] + [ValidateEnumeratedItems] public List Filters { get; set; } = []; #nullable disable diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs index 3d48b5f71d6..f973a350886 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptionsValidator.cs @@ -1,14 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#nullable disable +#nullable enable using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using Microsoft.Extensions.Options; namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options { - [OptionsValidator] partial class CollectionRuleOptionsValidator : IValidateOptions { private readonly IServiceProvider _serviceProvider; @@ -17,5 +18,69 @@ public CollectionRuleOptionsValidator(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } + + private static readonly RequiredAttribute RequiredAttribute = new RequiredAttribute(); + + public ValidateOptionsResult Validate(string? name, CollectionRuleOptions options) + { + ValidateOptionsResultBuilder? builder = null; + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Validate" : $"{name}.Validate"; + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(1); + + context.MemberName = "Validate"; + context.DisplayName = "CollectionRuleOptions.Validate"; + var iValidatableObjectResults = ((IValidatableObject)options).Validate(context); + if (iValidatableObjectResults != null) + { + foreach (var result in iValidatableObjectResults) + { + (builder ??= new()).AddResult(result); + } + } + + if (builder is not null) + { + return builder.Build(); + } + + context.MemberName = "Trigger"; + context.DisplayName = "CollectionRuleOptions.Trigger"; + validationAttributes.Add(RequiredAttribute); + if (!Validator.TryValidateValue(options.Trigger, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + if (options.Trigger is not null) + { + (builder ??= new()).AddResult(new CollectionRuleTriggerOptionsValidator(_serviceProvider).Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Trigger" : $"{name}.Trigger", options.Trigger)); + } + + if (options.Actions is not null) + { + var count = 0; + foreach (var o in options.Actions) + { + if (o is not null) + { + (builder ??= new()).AddResult(new CollectionRuleActionOptionsValidator(_serviceProvider).Validate(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}]" : $"{name}.Actions[{count}]", o)); + } + else + { + (builder ??= new()).AddError(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}] is null" : $"{name}.Actions[{count}] is null"); + } + count++; + } + } + + if (options.Limits is not null) + { + (builder ??= new()).AddResult(__CollectionRuleLimitsOptionsValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Limits" : $"{name}.Limits", options.Limits)); + } + + return builder is null ? ValidateOptionsResult.Success : builder.Build(); + } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Options/ValidationHelper.cs b/src/Tools/dotnet-monitor/CollectionRules/Options/ValidationHelper.cs index c99543df9c0..0c5230036ba 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Options/ValidationHelper.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Options/ValidationHelper.cs @@ -12,20 +12,6 @@ namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options { internal static class ValidationHelper { - public static void TryValidateItems(IEnumerable items, ValidationContext validationContext, ICollection results) - { - int index = 0; - foreach (object item in items) - { - ValidationContext itemContext = new(item, validationContext, validationContext.Items); - itemContext.MemberName = validationContext.MemberName + "[" + index.ToString() + "]"; - - Validator.TryValidateObject(item, itemContext, results); - - index++; - } - } - #nullable disable public static bool TryValidateOptions(Type optionsType, object options, ValidationContext validationContext, ICollection results) { diff --git a/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestCountTriggerFactory.cs b/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestCountTriggerFactory.cs index 59f808b96e7..4d427833c8e 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestCountTriggerFactory.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestCountTriggerFactory.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using System; using System.Globalization; +using Microsoft.Extensions.Options; namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers { @@ -48,17 +49,15 @@ public ICollectionRuleTrigger Create(IEndpointInfo endpointInfo, Action callback } } - internal sealed class AspNetRequestCountTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class AspNetRequestCountTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(AspNetRequestCountTriggerFactory); - public Type? OptionsType => typeof(AspNetRequestCountOptions); public string TriggerName => KnownCollectionRuleTriggers.AspNetRequestCount; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out AspNetRequestCountOptions options) { - var options = new AspNetRequestCountOptions(); + options = new AspNetRequestCountOptions(); settingsSection.Bind_AspNetRequestCountOptions(options); - settings = options; return true; } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestDurationTriggerFactory.cs b/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestDurationTriggerFactory.cs index cae2ed3ac1f..7cce21e2793 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestDurationTriggerFactory.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetRequestDurationTriggerFactory.cs @@ -54,17 +54,15 @@ public ICollectionRuleTrigger Create(IEndpointInfo endpointInfo, Action callback } } - internal sealed class AspNetRequestDurationTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class AspNetRequestDurationTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(AspNetRequestDurationTriggerFactory); - public Type? OptionsType => typeof(AspNetRequestDurationOptions); public string TriggerName => KnownCollectionRuleTriggers.AspNetRequestDuration; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out AspNetRequestDurationOptions options) { - var options = new AspNetRequestDurationOptions(); + options = new AspNetRequestDurationOptions(); settingsSection.Bind_AspNetRequestDurationOptions(options); - settings = options; return true; } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetResponseStatusTriggerFactory.cs b/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetResponseStatusTriggerFactory.cs index 2e4bce415dc..75756453255 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetResponseStatusTriggerFactory.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Triggers/AspNetResponseStatusTriggerFactory.cs @@ -9,6 +9,7 @@ using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Binder.SourceGeneration; +using Microsoft.Extensions.Options; using System; using System.Globalization; using System.Linq; @@ -63,17 +64,15 @@ private static StatusCodeRange ParseRange(string range) } } - internal sealed class AspNetResponseStatusTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class AspNetResponseStatusTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(AspNetResponseStatusTriggerFactory); - public Type? OptionsType => typeof(AspNetResponseStatusOptions); public string TriggerName => KnownCollectionRuleTriggers.AspNetResponseStatus; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out AspNetResponseStatusOptions options) { - var options = new AspNetResponseStatusOptions(); + options = new AspNetResponseStatusOptions(); settingsSection.Bind_AspNetResponseStatusOptions(options); - settings = options; return true; } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventCounterTriggerFactory.cs b/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventCounterTriggerFactory.cs index c2f9a4c8635..2c295ecc47f 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventCounterTriggerFactory.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventCounterTriggerFactory.cs @@ -113,62 +113,54 @@ internal static EventCounterOptions ToEventCounterOptions(IEventCounterShortcuts } } - internal sealed class EventCounterTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class EventCounterTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(EventCounterTriggerFactory); - public Type? OptionsType => typeof(EventCounterOptions); public string TriggerName => KnownCollectionRuleTriggers.EventCounter; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out EventCounterOptions options) { - var options = new EventCounterOptions(); + options = new EventCounterOptions(); settingsSection.Bind_EventCounterOptions(options); - settings = options; return true; } } - internal sealed class CPUUsageTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class CPUUsageTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(EventCounterTriggerFactory); - public Type? OptionsType => typeof(CPUUsageOptions); public string TriggerName => KnownCollectionRuleTriggers.CPUUsage; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out CPUUsageOptions options) { - var options = new CPUUsageOptions(); + options = new CPUUsageOptions(); settingsSection.Bind_CPUUsageOptions(options); - settings = options; return true; } } - internal sealed class GCHeapSizeTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class GCHeapSizeTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(EventCounterTriggerFactory); - public Type? OptionsType => typeof(GCHeapSizeOptions); public string TriggerName => KnownCollectionRuleTriggers.GCHeapSize; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out GCHeapSizeOptions options) { - var options = new GCHeapSizeOptions(); + options = new GCHeapSizeOptions(); settingsSection.Bind_GCHeapSizeOptions(options); - settings = options; return true; } } - internal sealed class ThreadpoolQueueLengthTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class ThreadpoolQueueLengthTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(EventCounterTriggerFactory); - public Type? OptionsType => typeof(ThreadpoolQueueLengthOptions); public string TriggerName => KnownCollectionRuleTriggers.ThreadpoolQueueLength; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out ThreadpoolQueueLengthOptions options) { - var options = new ThreadpoolQueueLengthOptions(); + options = new ThreadpoolQueueLengthOptions(); settingsSection.Bind_ThreadpoolQueueLengthOptions(options); - settings = options; return true; } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventMeterTriggerFactory.cs b/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventMeterTriggerFactory.cs index 41bd60e5bb9..40ce8677818 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventMeterTriggerFactory.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Triggers/EventMeterTriggerFactory.cs @@ -59,17 +59,15 @@ public ICollectionRuleTrigger Create(IEndpointInfo endpointInfo, Action callback } } - internal sealed class EventMeterTriggerDescriptor : ICollectionRuleTriggerDescriptor + [OptionsValidator] + internal sealed partial class EventMeterTriggerDescriptor : ICollectionRuleTriggerDescriptor { - public Type FactoryType => typeof(EventMeterTriggerFactory); - public Type? OptionsType => typeof(EventMeterOptions); public string TriggerName => KnownCollectionRuleTriggers.EventMeter; - public bool TryBindOptions(IConfigurationSection settingsSection, out object? settings) + public bool TryBindOptions(IConfigurationSection settingsSection, out EventMeterOptions options) { - var options = new EventMeterOptions(); + options = new EventMeterOptions(); settingsSection.Bind_EventMeterOptions(options); - settings = options; return true; } } diff --git a/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs b/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs index a11be043ac8..5fdd1b33bb1 100644 --- a/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs +++ b/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs @@ -60,7 +60,8 @@ public static IServiceCollection ConfigureDotnetMonitorDebug(this IServiceCollec public static IServiceCollection ConfigureGlobalCounter(this IServiceCollection services, IConfiguration configuration) { return services.Configure(configuration.GetSection(ConfigurationKeys.GlobalCounter)) - .AddSingleton, DataAnnotationValidateOptions>(); + .AddSingleton, GlobalCounterOptionsValidator>() + .AddSingleton, GlobalProviderOptionsValidator>(); } @@ -95,7 +96,7 @@ public static IServiceCollection ConfigureInProcessFeatures(this IServiceCollect public static IServiceCollection ConfigureMetrics(this IServiceCollection services, IConfiguration configuration) { return services.Configure(configuration.GetSection(ConfigurationKeys.Metrics)) - .AddSingleton, DataAnnotationValidateOptions>() + .AddSingleton, MetricsOptionsValidator>() .AddSingleton() .AddHostedService() .AddSingleton(); @@ -223,14 +224,14 @@ public static IServiceCollection RegisterCollectionRuleTrigger(this IServiceCollection services) where TFactory : class, ICollectionRuleTriggerFactory where TOptions : class, new() - where TDescriptor : class, ICollectionRuleTriggerDescriptor + where TDescriptor : class, ICollectionRuleTriggerDescriptor { services.AddSingleton(); services.AddSingleton>(); services.AddSingleton(); // NOTE: When opening collection rule triggers for extensibility, this should not be added for all registered triggers. // Each trigger should register its own IValidateOptions<> implementation (if it needs one). - services.AddSingleton, DataAnnotationValidateOptions>(); + services.AddSingleton, TDescriptor>(); return services; } diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs index 5a72422a248..cf4e39fd12c 100644 --- a/src/Tools/dotnet-monitor/Validators.cs +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -31,7 +31,7 @@ internal sealed partial class __EventMetricsMeterValidator__ var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "MeterName"; - context.DisplayName = string.IsNullOrEmpty(name) ? "EventMetricsMeter.MeterName" : $"{name}.MeterName"; + context.DisplayName = "EventMetricsMeter.MeterName"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MeterName, context, validationResults, validationAttributes)) @@ -72,7 +72,7 @@ internal sealed partial class __EventMetricsProviderValidator__ var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "ProviderName"; - context.DisplayName = string.IsNullOrEmpty(name) ? "EventMetricsProvider.ProviderName" : $"{name}.ProviderName"; + context.DisplayName = "EventMetricsProvider.ProviderName"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) @@ -113,7 +113,7 @@ internal sealed partial class __EventPipeProviderValidator__ var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "Name"; - context.DisplayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.Name" : $"{name}.Name"; + context.DisplayName = "EventPipeProvider.Name"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) @@ -122,7 +122,7 @@ internal sealed partial class __EventPipeProviderValidator__ } context.MemberName = "Keywords"; - context.DisplayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.Keywords" : $"{name}.Keywords"; + context.DisplayName = "EventPipeProvider.Keywords"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); @@ -132,7 +132,7 @@ internal sealed partial class __EventPipeProviderValidator__ } context.MemberName = "EventLevel"; - context.DisplayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.EventLevel" : $"{name}.EventLevel"; + context.DisplayName = "EventPipeProvider.EventLevel"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A4); @@ -165,7 +165,7 @@ partial class CollectDumpActionDescriptor global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -173,7 +173,7 @@ partial class CollectDumpActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "Type"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Type" : $"{name}.Type"; + context.DisplayName = "CollectDumpOptions.Type"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A5); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) { @@ -181,7 +181,7 @@ partial class CollectDumpActionDescriptor } context.MemberName = "Egress"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Egress" : $"{name}.Egress"; + context.DisplayName = "CollectDumpOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); @@ -215,7 +215,7 @@ partial class CollectExceptionsActionDescriptor global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -223,7 +223,7 @@ partial class CollectExceptionsActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "Egress"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Egress" : $"{name}.Egress"; + context.DisplayName = "CollectExceptionsOptions.Egress"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) @@ -232,7 +232,7 @@ partial class CollectExceptionsActionDescriptor } context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Validate" : $"{name}.Validate"; + context.DisplayName = "CollectExceptionsOptions.Validate"; (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); @@ -259,7 +259,7 @@ partial class CollectGCDumpActionDescriptor global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectGCDumpOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -267,7 +267,7 @@ partial class CollectGCDumpActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "Egress"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectGCDumpOptions.Egress" : $"{name}.Egress"; + context.DisplayName = "CollectGCDumpOptions.Egress"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) @@ -299,7 +299,7 @@ partial class CollectLiveMetricsActionDescriptor global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -341,7 +341,7 @@ partial class CollectLiveMetricsActionDescriptor } context.MemberName = "Duration"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Duration" : $"{name}.Duration"; + context.DisplayName = "CollectLiveMetricsOptions.Duration"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) { @@ -349,7 +349,7 @@ partial class CollectLiveMetricsActionDescriptor } context.MemberName = "Egress"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Egress" : $"{name}.Egress"; + context.DisplayName = "CollectLiveMetricsOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); @@ -383,7 +383,7 @@ partial class CollectLogsActionDescriptor global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -391,7 +391,7 @@ partial class CollectLogsActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "DefaultLevel"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.DefaultLevel" : $"{name}.DefaultLevel"; + context.DisplayName = "CollectLogsOptions.DefaultLevel"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A9); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.DefaultLevel, context, validationResults, validationAttributes)) { @@ -399,7 +399,7 @@ partial class CollectLogsActionDescriptor } context.MemberName = "Duration"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Duration" : $"{name}.Duration"; + context.DisplayName = "CollectLogsOptions.Duration"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); @@ -409,7 +409,7 @@ partial class CollectLogsActionDescriptor } context.MemberName = "Egress"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Egress" : $"{name}.Egress"; + context.DisplayName = "CollectLogsOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); @@ -420,7 +420,7 @@ partial class CollectLogsActionDescriptor } context.MemberName = "Format"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Format" : $"{name}.Format"; + context.DisplayName = "CollectLogsOptions.Format"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A10); @@ -430,7 +430,7 @@ partial class CollectLogsActionDescriptor } context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Validate" : $"{name}.Validate"; + context.DisplayName = "CollectLogsOptions.Validate"; (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); @@ -457,7 +457,7 @@ partial class CollectStacksActionDescriptor global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -465,7 +465,7 @@ partial class CollectStacksActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "Egress"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Egress" : $"{name}.Egress"; + context.DisplayName = "CollectStacksOptions.Egress"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) @@ -474,7 +474,7 @@ partial class CollectStacksActionDescriptor } context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Validate" : $"{name}.Validate"; + context.DisplayName = "CollectStacksOptions.Validate"; (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); @@ -501,7 +501,7 @@ partial class CollectTraceActionDescriptor global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif @@ -509,7 +509,7 @@ partial class CollectTraceActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "Profile"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Profile" : $"{name}.Profile"; + context.DisplayName = "CollectTraceOptions.Profile"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A11); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Profile, context, validationResults, validationAttributes)) { @@ -534,7 +534,7 @@ partial class CollectTraceActionDescriptor } context.MemberName = "BufferSizeMegabytes"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.BufferSizeMegabytes" : $"{name}.BufferSizeMegabytes"; + context.DisplayName = "CollectTraceOptions.BufferSizeMegabytes"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A12); @@ -544,7 +544,7 @@ partial class CollectTraceActionDescriptor } context.MemberName = "Duration"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Duration" : $"{name}.Duration"; + context.DisplayName = "CollectTraceOptions.Duration"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); @@ -554,7 +554,7 @@ partial class CollectTraceActionDescriptor } context.MemberName = "Egress"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Egress" : $"{name}.Egress"; + context.DisplayName = "CollectTraceOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); @@ -570,7 +570,7 @@ partial class CollectTraceActionDescriptor } context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Validate" : $"{name}.Validate"; + context.DisplayName = "CollectTraceOptions.Validate"; (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); @@ -605,7 +605,7 @@ partial class ExecuteActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(1); context.MemberName = "Path"; - context.DisplayName = string.IsNullOrEmpty(name) ? "ExecuteOptions.Path" : $"{name}.Path"; + context.DisplayName = "ExecuteOptions.Path"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) { @@ -644,7 +644,7 @@ partial class GetEnvironmentVariableActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(1); context.MemberName = "Name"; - context.DisplayName = string.IsNullOrEmpty(name) ? "GetEnvironmentVariableOptions.Name" : $"{name}.Name"; + context.DisplayName = "GetEnvironmentVariableOptions.Name"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) { @@ -683,7 +683,7 @@ partial class LoadProfilerActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(2); context.MemberName = "Path"; - context.DisplayName = string.IsNullOrEmpty(name) ? "LoadProfilerOptions.Path" : $"{name}.Path"; + context.DisplayName = "LoadProfilerOptions.Path"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) { @@ -691,7 +691,7 @@ partial class LoadProfilerActionDescriptor } context.MemberName = "Clsid"; - context.DisplayName = string.IsNullOrEmpty(name) ? "LoadProfilerOptions.Clsid" : $"{name}.Clsid"; + context.DisplayName = "LoadProfilerOptions.Clsid"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); @@ -733,7 +733,7 @@ partial class SetEnvironmentVariableActionDescriptor var validationAttributes = new global::System.Collections.Generic.List(1); context.MemberName = "Name"; - context.DisplayName = string.IsNullOrEmpty(name) ? "SetEnvironmentVariableOptions.Name" : $"{name}.Name"; + context.DisplayName = "SetEnvironmentVariableOptions.Name"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) { @@ -773,7 +773,7 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ var validationAttributes = new global::System.Collections.Generic.List(1); context.MemberName = "ActionCount"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.ActionCount" : $"{name}.ActionCount"; + context.DisplayName = "CollectionRuleLimitsOptions.ActionCount"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ActionCount, context, validationResults, validationAttributes)) { @@ -781,7 +781,7 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ } context.MemberName = "ActionCountSlidingWindowDuration"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.ActionCountSlidingWindowDuration" : $"{name}.ActionCountSlidingWindowDuration"; + context.DisplayName = "CollectionRuleLimitsOptions.ActionCountSlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); @@ -791,7 +791,7 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ } context.MemberName = "RuleDuration"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.RuleDuration" : $"{name}.RuleDuration"; + context.DisplayName = "CollectionRuleLimitsOptions.RuleDuration"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A15); @@ -833,7 +833,7 @@ internal sealed partial class __TraceEventFilterValidator__ var validationAttributes = new global::System.Collections.Generic.List(1); context.MemberName = "ProviderName"; - context.DisplayName = string.IsNullOrEmpty(name) ? "TraceEventFilter.ProviderName" : $"{name}.ProviderName"; + context.DisplayName = "TraceEventFilter.ProviderName"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) { @@ -841,7 +841,7 @@ internal sealed partial class __TraceEventFilterValidator__ } context.MemberName = "EventName"; - context.DisplayName = string.IsNullOrEmpty(name) ? "TraceEventFilter.EventName" : $"{name}.EventName"; + context.DisplayName = "TraceEventFilter.EventName"; validationResults.Clear(); validationAttributes.Clear(); validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); @@ -882,7 +882,7 @@ partial class CollectionRuleActionOptionsValidator var validationAttributes = new global::System.Collections.Generic.List(1); context.MemberName = "Type"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Type" : $"{name}.Type"; + context.DisplayName = "CollectionRuleActionOptions.Type"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) { @@ -890,7 +890,7 @@ partial class CollectionRuleActionOptionsValidator } context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; + context.DisplayName = "CollectionRuleActionOptions.Validate"; (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); @@ -899,7 +899,7 @@ partial class CollectionRuleActionOptionsValidator } namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options { - partial class CollectionRuleOptionsValidator + partial class CollectionRuleTriggerOptionsValidator { /// /// Validates a specific named options instance (or all when is ). @@ -912,11 +912,11 @@ partial class CollectionRuleOptionsValidator [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "The created ValidationContext object is used in a way that never call reflection")] #endif - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleOptions options) + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER - string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Validate" : $"{name}.Validate"; + string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); @@ -924,52 +924,88 @@ partial class CollectionRuleOptionsValidator var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); - context.MemberName = "Trigger"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Trigger" : $"{name}.Trigger"; + context.MemberName = "Type"; + context.DisplayName = "CollectionRuleTriggerOptions.Type"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Trigger, context, validationResults, validationAttributes)) + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - if (options.Trigger is not null) + context.MemberName = "Validate"; + context.DisplayName = "CollectionRuleTriggerOptions.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers +{ + partial class EventCounterOptions + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "EventCounterOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "ProviderName"; + context.DisplayName = "EventCounterOptions.ProviderName"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) { - (builder ??= new()).AddResult(new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptionsValidator(_serviceProvider).Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Trigger" : $"{name}.Trigger", options.Trigger)); + (builder ??= new()).AddResults(validationResults); } - if (options.Actions is not null) + context.MemberName = "CounterName"; + context.DisplayName = "EventCounterOptions.CounterName"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.CounterName, context, validationResults, validationAttributes)) { - var count = 0; - foreach (var o in options.Actions) - { - if (o is not null) - { - (builder ??= new()).AddResult(new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptionsValidator(_serviceProvider).Validate(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}]" : $"{name}.Actions[{count}]", o)); - } - else - { - (builder ??= new()).AddError(string.IsNullOrEmpty(name) ? $"CollectionRuleOptions.Actions[{count}] is null" : $"{name}.Actions[{count}] is null"); - } - count++; - } + (builder ??= new()).AddResults(validationResults); } - if (options.Limits is not null) + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "EventCounterOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.__CollectionRuleLimitsOptionsValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Limits" : $"{name}.Limits", options.Limits)); + (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleOptions.Validate" : $"{name}.Validate"; + context.DisplayName = "EventCounterOptions.Validate"; (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); } } } -namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers { - partial class CollectionRuleTriggerOptionsValidator + partial class AspNetRequestCountTriggerDescriptor { /// /// Validates a specific named options instance (or all when is ). @@ -982,28 +1018,482 @@ partial class CollectionRuleTriggerOptionsValidator [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "The created ValidationContext object is used in a way that never call reflection")] #endif - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestCountOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; #if NET10_0_OR_GREATER - string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); + string displayName = string.IsNullOrEmpty(name) ? "AspNetRequestCountOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "RequestCount"; + context.DisplayName = "AspNetRequestCountOptions.RequestCount"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A16); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RequestCount, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "AspNetRequestCountOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers +{ + partial class AspNetRequestDurationTriggerDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestDurationOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "AspNetRequestDurationOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(2); + + context.MemberName = "RequestCount"; + context.DisplayName = "AspNetRequestDurationOptions.RequestCount"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A16); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RequestCount, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "RequestDuration"; + context.DisplayName = "AspNetRequestDurationOptions.RequestDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A17); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RequestDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "AspNetRequestDurationOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers +{ + partial class AspNetResponseStatusTriggerDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetResponseStatusOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "AspNetResponseStatusOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(3); + + context.MemberName = "StatusCodes"; + context.DisplayName = "AspNetResponseStatusOptions.StatusCodes"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A18); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.StatusCodes, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "ResponseCount"; + context.DisplayName = "AspNetResponseStatusOptions.ResponseCount"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A19); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ResponseCount, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "AspNetResponseStatusOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers +{ + partial class CPUUsageTriggerDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.CPUUsageOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "CPUUsageOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); #else var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); - context.MemberName = "Type"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Type" : $"{name}.Type"; + context.MemberName = "GreaterThan"; + context.DisplayName = "CPUUsageOptions.GreaterThan"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A20); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "LessThan"; + context.DisplayName = "CPUUsageOptions.LessThan"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A20); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "CPUUsageOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = "CPUUsageOptions.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers +{ + partial class EventCounterTriggerDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "EventCounterOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "ProviderName"; + context.DisplayName = "EventCounterOptions.ProviderName"; validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "CounterName"; + context.DisplayName = "EventCounterOptions.CounterName"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.CounterName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "EventCounterOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = "EventCounterOptions.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers +{ + partial class EventMeterTriggerDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventMeterOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "EventMeterOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "MeterName"; + context.DisplayName = "EventMeterOptions.MeterName"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MeterName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "InstrumentName"; + context.DisplayName = "EventMeterOptions.InstrumentName"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.InstrumentName, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "EventMeterOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "HistogramPercentile"; + context.DisplayName = "EventMeterOptions.HistogramPercentile"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A20); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.HistogramPercentile, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; - context.DisplayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; + context.DisplayName = "EventMeterOptions.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers +{ + partial class GCHeapSizeTriggerDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.GCHeapSizeOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "GCHeapSizeOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "GreaterThan"; + context.DisplayName = "GCHeapSizeOptions.GreaterThan"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "LessThan"; + context.DisplayName = "GCHeapSizeOptions.LessThan"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "GCHeapSizeOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = "GCHeapSizeOptions.Validate"; + (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + + return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + } + } +} +namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Triggers +{ + partial class ThreadpoolQueueLengthTriggerDescriptor + { + /// + /// Validates a specific named options instance (or all when is ). + /// + /// The name of the options instance being validated. + /// The options instance. + /// Validation result. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + #if !NET10_0_OR_GREATER + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", + Justification = "The created ValidationContext object is used in a way that never call reflection")] + #endif + public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.ThreadpoolQueueLengthOptions options) + { + global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + #if NET10_0_OR_GREATER + string displayName = string.IsNullOrEmpty(name) ? "ThreadpoolQueueLengthOptions.Validate" : $"{name}.Validate"; + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); + #else + var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); + #endif + var validationResults = new global::System.Collections.Generic.List(); + var validationAttributes = new global::System.Collections.Generic.List(1); + + context.MemberName = "GreaterThan"; + context.DisplayName = "ThreadpoolQueueLengthOptions.GreaterThan"; + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "LessThan"; + context.DisplayName = "ThreadpoolQueueLengthOptions.LessThan"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "SlidingWindowDuration"; + context.DisplayName = "ThreadpoolQueueLengthOptions.SlidingWindowDuration"; + validationResults.Clear(); + validationAttributes.Clear(); + validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); + if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + { + (builder ??= new()).AddResults(validationResults); + } + + context.MemberName = "Validate"; + context.DisplayName = "ThreadpoolQueueLengthOptions.Validate"; (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); @@ -1064,6 +1554,38 @@ file static class __Attributes typeof(global::System.TimeSpan), "00:00:01", "365.00:00:00"); + + internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A16 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute() + { + ErrorMessageResourceName = "ErrorMessage_NoDefaultRequestCount", + ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + }; + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A17 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + typeof(global::System.TimeSpan), + "00:00:00", + "01:00:00"); + + internal static readonly global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.RegularExpressionsAttribute A18 = new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.RegularExpressionsAttribute( + "[1-5][0-9]{2}(-[1-5][0-9]{2})?") + { + ErrorMessageResourceName = "ErrorMessage_StatusCodesRegularExpressionDoesNotMatch", + ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + }; + + internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A19 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute() + { + ErrorMessageResourceName = "ErrorMessage_NoDefaultResponseCount", + ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + }; + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A20 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + (double)0, + (double)100); + + internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A21 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( + (double)0, + (double)1.7976931348623157E+308); } } namespace __OptionValidationStaticInstances From 2935446e8e987bccc6fefef0c024811264f86497 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 15 May 2025 09:58:05 -0700 Subject: [PATCH 06/13] Fix bind callsites --- .../CollectionRules/Actions/CollectGCDumpAction.cs | 3 ++- .../CollectionRules/Actions/CollectLiveMetricsAction.cs | 3 ++- .../CollectionRules/Actions/CollectLogsAction.cs | 3 ++- .../CollectionRules/Actions/CollectStacksAction.cs | 3 ++- .../CollectionRules/Actions/CollectTraceAction.cs | 3 ++- .../dotnet-monitor/CollectionRules/Actions/ExecuteAction.cs | 3 ++- .../CollectionRules/Actions/GetEnvironmentVariableAction.cs | 3 ++- .../CollectionRules/Actions/LoadProfilerAction.cs | 3 ++- .../CollectionRules/Actions/SetEnvironmentVariableAction.cs | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs index c4c327cccdf..ca40464c397 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectGCDumpAction.cs @@ -4,6 +4,7 @@ using Microsoft.Diagnostics.Monitoring.WebApi; using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System; @@ -78,7 +79,7 @@ public CollectGCDumpActionDescriptor(IServiceProvider serviceProvider) public void BindOptions(IConfigurationSection settingsSection, out CollectGCDumpOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_CollectGCDumpOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs index 4a769f1f380..9e98e3504e0 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLiveMetricsAction.cs @@ -7,6 +7,7 @@ using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions; using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System; @@ -113,7 +114,7 @@ public CollectLiveMetricsActionDescriptor(IServiceProvider serviceProvider) public void BindOptions(IConfigurationSection settingsSection, out CollectLiveMetricsOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_CollectLiveMetricsOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs index 979df57b384..a88037dd25c 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectLogsAction.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -102,7 +103,7 @@ public CollectLogsActionDescriptor(IServiceProvider serviceProvider) public void BindOptions(IConfigurationSection settingsSection, out CollectLogsOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_CollectLogsOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs index 61a4ea22eeb..3de3fece73e 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectStacksAction.cs @@ -6,6 +6,7 @@ using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.Options; using System; using System.ComponentModel.DataAnnotations; @@ -90,7 +91,7 @@ public CollectStacksActionDescriptor(IServiceProvider serviceProvider) public void BindOptions(IConfigurationSection settingsSection, out CollectStacksOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_CollectStacksOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs index df46850e0bc..52d57e1297c 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/CollectTraceAction.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using System; using System.ComponentModel.DataAnnotations; using Utils = Microsoft.Diagnostics.Monitoring.WebApi.Utilities; @@ -125,7 +126,7 @@ public CollectTraceActionDescriptor(IServiceProvider serviceProvider) public void BindOptions(IConfigurationSection settingsSection, out CollectTraceOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_CollectTraceOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/ExecuteAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/ExecuteAction.cs index 82fcef1e6a1..2bd72e160b1 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/ExecuteAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/ExecuteAction.cs @@ -6,6 +6,7 @@ using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions; using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -117,7 +118,7 @@ internal sealed partial class ExecuteActionDescriptor : ICollectionRuleActionDes public void BindOptions(IConfigurationSection settingsSection, out ExecuteOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_ExecuteOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/GetEnvironmentVariableAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/GetEnvironmentVariableAction.cs index b45407b9d9c..2659886f005 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/GetEnvironmentVariableAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/GetEnvironmentVariableAction.cs @@ -7,6 +7,7 @@ using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -95,7 +96,7 @@ internal sealed partial class GetEnvironmentVariableActionDescriptor : ICollecti public void BindOptions(IConfigurationSection settingsSection, out GetEnvironmentVariableOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_GetEnvironmentVariableOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/LoadProfilerAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/LoadProfilerAction.cs index f52af51ac90..5fcd6c53e0d 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/LoadProfilerAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/LoadProfilerAction.cs @@ -7,6 +7,7 @@ using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.Options; using System; using System.ComponentModel.DataAnnotations; @@ -80,7 +81,7 @@ internal sealed partial class LoadProfilerActionDescriptor : ICollectionRuleActi public void BindOptions(IConfigurationSection settingsSection, out LoadProfilerOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_LoadProfilerOptions(options); } } } diff --git a/src/Tools/dotnet-monitor/CollectionRules/Actions/SetEnvironmentVariableAction.cs b/src/Tools/dotnet-monitor/CollectionRules/Actions/SetEnvironmentVariableAction.cs index a4114afcfd1..27a6c787464 100644 --- a/src/Tools/dotnet-monitor/CollectionRules/Actions/SetEnvironmentVariableAction.cs +++ b/src/Tools/dotnet-monitor/CollectionRules/Actions/SetEnvironmentVariableAction.cs @@ -7,6 +7,7 @@ using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration.Binder.SourceGeneration; using Microsoft.Extensions.Options; using System; using System.ComponentModel.DataAnnotations; @@ -80,7 +81,7 @@ internal sealed partial class SetEnvironmentVariableActionDescriptor : ICollecti public void BindOptions(IConfigurationSection settingsSection, out SetEnvironmentVariableOptions options) { options = new(); - settingsSection.Bind(options); + settingsSection.Bind_SetEnvironmentVariableOptions(options); } } } From 83e79f4b9060966895e6bbf6447f335d549af955 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 7 Jul 2025 22:28:50 +0000 Subject: [PATCH 07/13] Remove NET10_0_OR_GREATER checks --- .../Validators.cs | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs index 11b6c4bbb62..8e8215e93a9 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs @@ -14,19 +14,11 @@ internal sealed partial class __MetricProviderValidator__ /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricProvider options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "MetricProvider.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -53,19 +45,11 @@ partial class GlobalCounterOptionsValidator /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalCounterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "GlobalCounterOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -116,19 +100,11 @@ partial class GlobalProviderOptionsValidator /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalProviderOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "GlobalProviderOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -155,19 +131,11 @@ partial class MetricsOptionsValidator /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "MetricsOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -211,19 +179,11 @@ partial class FileSystemEgressProviderOptionsValidator /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem.FileSystemEgressProviderOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "FileSystemEgressProviderOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); From 409b5b908c4d1817ec935a8431d16887056941e8 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 7 Jul 2025 22:05:00 +0000 Subject: [PATCH 08/13] Remove GeneratedCodeAttribute --- .../Validators.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs index 8e8215e93a9..7f80aebfc58 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs @@ -4,7 +4,6 @@ #pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 namespace Microsoft.Diagnostics.Monitoring.WebApi { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __MetricProviderValidator__ { /// @@ -13,7 +12,6 @@ internal sealed partial class __MetricProviderValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricProvider options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -44,7 +42,6 @@ partial class GlobalCounterOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalCounterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -99,7 +96,6 @@ partial class GlobalProviderOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalProviderOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -130,7 +126,6 @@ partial class MetricsOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -178,7 +173,6 @@ partial class FileSystemEgressProviderOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem.FileSystemEgressProviderOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -211,7 +205,6 @@ partial class FileSystemEgressProviderOptionsValidator } namespace __OptionValidationStaticInstances { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] file static class __Attributes { internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A1 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute(); @@ -227,14 +220,12 @@ file static class __Attributes } namespace __OptionValidationStaticInstances { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] file static class __Validators { } } namespace __OptionValidationGeneratedAttributes { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] file class __SourceGen__RangeAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute { From 5bd0ebd03048fcdd2415b2f527b89e9cd7f3d8de Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 7 Jul 2025 22:39:42 +0000 Subject: [PATCH 09/13] Clean up namespaces --- .../Validators.cs | 158 +++++++++--------- 1 file changed, 83 insertions(+), 75 deletions(-) diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs index 7f80aebfc58..ec05d25fa75 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs @@ -1,8 +1,16 @@ - - // - #nullable enable - #pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 - namespace Microsoft.Diagnostics.Monitoring.WebApi +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Globalization; + +// +#nullable enable +#pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 +namespace Microsoft.Diagnostics.Monitoring.WebApi { internal sealed partial class __MetricProviderValidator__ { @@ -12,23 +20,23 @@ internal sealed partial class __MetricProviderValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricProvider options) + public static ValidateOptionsResult Validate(string? name, MetricProvider options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "MetricProvider.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "ProviderName"; context.DisplayName = "MetricProvider.ProviderName"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A1); + if (!Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -42,18 +50,18 @@ partial class GlobalCounterOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalCounterOptions options) + public ValidateOptionsResult Validate(string? name, GlobalCounterOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "GlobalCounterOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "IntervalSeconds"; context.DisplayName = "GlobalCounterOptions.IntervalSeconds"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.IntervalSeconds, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A2); + if (!Validator.TryValidateValue(options.IntervalSeconds, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -62,8 +70,8 @@ partial class GlobalCounterOptionsValidator context.DisplayName = "GlobalCounterOptions.MaxHistograms"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MaxHistograms, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A3); + if (!Validator.TryValidateValue(options.MaxHistograms, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -72,17 +80,17 @@ partial class GlobalCounterOptionsValidator context.DisplayName = "GlobalCounterOptions.MaxTimeSeries"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MaxTimeSeries, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A3); + if (!Validator.TryValidateValue(options.MaxTimeSeries, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = string.IsNullOrEmpty(name) ? "GlobalCounterOptions.Validate" : $"{name}.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -96,23 +104,23 @@ partial class GlobalProviderOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.GlobalProviderOptions options) + public ValidateOptionsResult Validate(string? name, GlobalProviderOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "GlobalProviderOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "IntervalSeconds"; context.DisplayName = "GlobalProviderOptions.IntervalSeconds"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.IntervalSeconds, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A2); + if (!Validator.TryValidateValue(options.IntervalSeconds, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -126,18 +134,18 @@ partial class MetricsOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.MetricsOptions options) + public ValidateOptionsResult Validate(string? name, MetricsOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "MetricsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "MetricCount"; context.DisplayName = "MetricsOptions.MetricCount"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MetricCount, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A3); + if (!Validator.TryValidateValue(options.MetricCount, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -149,7 +157,7 @@ partial class MetricsOptionsValidator { if (o is not null) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.__MetricProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"MetricsOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); + (builder ??= new()).AddResult(__MetricProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"MetricsOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); } else { @@ -159,7 +167,7 @@ partial class MetricsOptionsValidator } } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -173,18 +181,18 @@ partial class FileSystemEgressProviderOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem.FileSystemEgressProviderOptions options) + public ValidateOptionsResult Validate(string? name, FileSystemEgressProviderOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "FileSystemEgressProviderOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "DirectoryPath"; context.DisplayName = "FileSystemEgressProviderOptions.DirectoryPath"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.DirectoryPath, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A1); + if (!Validator.TryValidateValue(options.DirectoryPath, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -193,21 +201,21 @@ partial class FileSystemEgressProviderOptionsValidator context.DisplayName = "FileSystemEgressProviderOptions.CopyBufferSize"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.CopyBufferSize, context, validationResults, validationAttributes)) + validationAttributes.Add(__OptionValidationStaticInstances.__Attributes.A3); + if (!Validator.TryValidateValue(options.CopyBufferSize, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } namespace __OptionValidationStaticInstances { - file static class __Attributes + static class __Attributes { - internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A1 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute(); + internal static readonly RequiredAttribute A1 = new RequiredAttribute(); internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A2 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( (double)1, @@ -220,14 +228,14 @@ file static class __Attributes } namespace __OptionValidationStaticInstances { - file static class __Validators + static class __Validators { } } namespace __OptionValidationGeneratedAttributes { - [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] - file class __SourceGen__RangeAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + class __SourceGen__RangeAttribute : ValidationAttribute { public __SourceGen__RangeAttribute(int minimum, int maximum) : base() { @@ -241,7 +249,7 @@ public __SourceGen__RangeAttribute(double minimum, double maximum) : base() Maximum = maximum; OperandType = typeof(double); } - public __SourceGen__RangeAttribute(global::System.Type type, string minimum, string maximum) : base() + public __SourceGen__RangeAttribute(Type type, string minimum, string maximum) : base() { OperandType = type; _needToConvertMinMax = true; @@ -252,11 +260,11 @@ public __SourceGen__RangeAttribute(global::System.Type type, string minimum, str public object Maximum { get; private set; } public bool MinimumIsExclusive { get; set; } public bool MaximumIsExclusive { get; set; } - public global::System.Type OperandType { get; } + public Type OperandType { get; } public bool ParseLimitsInInvariantCulture { get; set; } public bool ConvertValueInInvariantCulture { get; set; } public override string FormatErrorMessage(string name) => - string.Format(global::System.Globalization.CultureInfo.CurrentCulture, GetValidationErrorMessage(), name, Minimum, Maximum); + string.Format(CultureInfo.CurrentCulture, GetValidationErrorMessage(), name, Minimum, Maximum); private readonly bool _needToConvertMinMax; private volatile bool _initialized; private readonly object _lock = new(); @@ -272,22 +280,22 @@ public override bool IsValid(object? value) { if (Minimum is null || Maximum is null) { - throw new global::System.InvalidOperationException(MinMaxError); + throw new InvalidOperationException(MinMaxError); } if (_needToConvertMinMax) { - System.Globalization.CultureInfo culture = ParseLimitsInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; - Minimum = ConvertValue(Minimum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); - Maximum = ConvertValue(Maximum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); + CultureInfo culture = ParseLimitsInInvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture; + Minimum = ConvertValue(Minimum, culture) ?? throw new InvalidOperationException(MinMaxError); + Maximum = ConvertValue(Maximum, culture) ?? throw new InvalidOperationException(MinMaxError); } - int cmp = ((global::System.IComparable)Minimum).CompareTo((global::System.IComparable)Maximum); + int cmp = ((IComparable)Minimum).CompareTo((IComparable)Maximum); if (cmp > 0) { - throw new global::System.InvalidOperationException("The maximum value '{Maximum}' must be greater than or equal to the minimum value '{Minimum}'."); + throw new InvalidOperationException("The maximum value '{Maximum}' must be greater than or equal to the minimum value '{Minimum}'."); } else if (cmp == 0 && (MinimumIsExclusive || MaximumIsExclusive)) { - throw new global::System.InvalidOperationException("Cannot use exclusive bounds when the maximum value is equal to the minimum value."); + throw new InvalidOperationException("Cannot use exclusive bounds when the maximum value is equal to the minimum value."); } _initialized = true; } @@ -299,20 +307,20 @@ public override bool IsValid(object? value) return true; } - System.Globalization.CultureInfo formatProvider = ConvertValueInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; + CultureInfo formatProvider = ConvertValueInInvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture; object? convertedValue; try { convertedValue = ConvertValue(value, formatProvider); } - catch (global::System.Exception e) when (e is global::System.FormatException or global::System.InvalidCastException or global::System.NotSupportedException) + catch (Exception e) when (e is FormatException or InvalidCastException or NotSupportedException) { return false; } - var min = (global::System.IComparable)Minimum; - var max = (global::System.IComparable)Maximum; + var min = (IComparable)Minimum; + var max = (IComparable)Maximum; return (MinimumIsExclusive ? min.CompareTo(convertedValue) < 0 : min.CompareTo(convertedValue) <= 0) && @@ -328,15 +336,15 @@ private string GetValidationErrorMessage() (true, true) => "The field {0} must be between {1} exclusive and {2} exclusive.", }; } - private object? ConvertValue(object? value, System.Globalization.CultureInfo formatProvider) + private object? ConvertValue(object? value, CultureInfo formatProvider) { if (value is string stringValue) { - value = global::System.Convert.ChangeType(stringValue, OperandType, formatProvider); + value = Convert.ChangeType(stringValue, OperandType, formatProvider); } else { - value = global::System.Convert.ChangeType(value, OperandType, formatProvider); + value = Convert.ChangeType(value, OperandType, formatProvider); } return value; } From db23cd2e91a0b859789acdb8cf942af9c0c4eec3 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 7 Jul 2025 22:46:04 +0000 Subject: [PATCH 10/13] Remove ifdefs from dotnet-monitor validators --- src/Tools/dotnet-monitor/Validators.cs | 224 +------------------------ 1 file changed, 4 insertions(+), 220 deletions(-) diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs index cf4e39fd12c..b6ba6311f7c 100644 --- a/src/Tools/dotnet-monitor/Validators.cs +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -1,8 +1,8 @@  - // - #nullable enable - #pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 - namespace Microsoft.Diagnostics.Monitoring.WebApi.Models +// +#nullable enable +#pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 +namespace Microsoft.Diagnostics.Monitoring.WebApi.Models { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __EventMetricsMeterValidator__ @@ -14,19 +14,11 @@ internal sealed partial class __EventMetricsMeterValidator__ /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsMeter options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "EventMetricsMeter.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -55,19 +47,11 @@ internal sealed partial class __EventMetricsProviderValidator__ /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsProvider options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "EventMetricsProvider.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -96,19 +80,11 @@ internal sealed partial class __EventPipeProviderValidator__ /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventPipeProvider options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -156,19 +132,11 @@ partial class CollectDumpActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectDumpOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -206,19 +174,11 @@ partial class CollectExceptionsActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectExceptionsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -250,19 +210,11 @@ partial class CollectGCDumpActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectGCDumpOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectGCDumpOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -290,19 +242,11 @@ partial class CollectLiveMetricsActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLiveMetricsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -374,19 +318,11 @@ partial class CollectLogsActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLogsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -448,19 +384,11 @@ partial class CollectStacksActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectStacksOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -492,19 +420,11 @@ partial class CollectTraceActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectTraceOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -588,19 +508,11 @@ partial class ExecuteActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ExecuteOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "ExecuteOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -627,19 +539,11 @@ partial class GetEnvironmentVariableActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.GetEnvironmentVariableOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "GetEnvironmentVariableOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -666,19 +570,11 @@ partial class LoadProfilerActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.LoadProfilerOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "LoadProfilerOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -716,19 +612,11 @@ partial class SetEnvironmentVariableActionDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.SetEnvironmentVariableOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "SetEnvironmentVariableOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -756,19 +644,11 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleLimitsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -816,19 +696,11 @@ internal sealed partial class __TraceEventFilterValidator__ /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.TraceEventFilter options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "TraceEventFilter.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -865,19 +737,11 @@ partial class CollectionRuleActionOptionsValidator /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -908,19 +772,11 @@ partial class CollectionRuleTriggerOptionsValidator /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -951,19 +807,11 @@ partial class EventCounterOptions /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "EventCounterOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -1014,19 +862,11 @@ partial class AspNetRequestCountTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestCountOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "AspNetRequestCountOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -1064,19 +904,11 @@ partial class AspNetRequestDurationTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestDurationOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "AspNetRequestDurationOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(2); @@ -1124,19 +956,11 @@ partial class AspNetResponseStatusTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetResponseStatusOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "AspNetResponseStatusOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(3); @@ -1186,19 +1010,11 @@ partial class CPUUsageTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.CPUUsageOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "CPUUsageOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -1249,19 +1065,11 @@ partial class EventCounterTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "EventCounterOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -1312,19 +1120,11 @@ partial class EventMeterTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventMeterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "EventMeterOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -1385,19 +1185,11 @@ partial class GCHeapSizeTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.GCHeapSizeOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "GCHeapSizeOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); @@ -1448,19 +1240,11 @@ partial class ThreadpoolQueueLengthTriggerDescriptor /// The options instance. /// Validation result. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] - #if !NET10_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", - Justification = "The created ValidationContext object is used in a way that never call reflection")] - #endif public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.ThreadpoolQueueLengthOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; - #if NET10_0_OR_GREATER string displayName = string.IsNullOrEmpty(name) ? "ThreadpoolQueueLengthOptions.Validate" : $"{name}.Validate"; var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - #else - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options); - #endif var validationResults = new global::System.Collections.Generic.List(); var validationAttributes = new global::System.Collections.Generic.List(1); From de44595477064f8dd7f6cd07f50865c9c6a68afc Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 7 Jul 2025 22:51:26 +0000 Subject: [PATCH 11/13] Remove GeneratedCode from dotnet-monitor validators --- src/Tools/dotnet-monitor/Validators.cs | 41 +++----------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs index b6ba6311f7c..78de0f901f8 100644 --- a/src/Tools/dotnet-monitor/Validators.cs +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -1,10 +1,11 @@ - +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + // #nullable enable #pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 namespace Microsoft.Diagnostics.Monitoring.WebApi.Models { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __EventMetricsMeterValidator__ { /// @@ -13,7 +14,6 @@ internal sealed partial class __EventMetricsMeterValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsMeter options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -37,7 +37,6 @@ internal sealed partial class __EventMetricsMeterValidator__ } namespace Microsoft.Diagnostics.Monitoring.WebApi.Models { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __EventMetricsProviderValidator__ { /// @@ -46,7 +45,6 @@ internal sealed partial class __EventMetricsProviderValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsProvider options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -70,7 +68,6 @@ internal sealed partial class __EventMetricsProviderValidator__ } namespace Microsoft.Diagnostics.Monitoring.WebApi.Models { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __EventPipeProviderValidator__ { /// @@ -79,7 +76,6 @@ internal sealed partial class __EventPipeProviderValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventPipeProvider options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -131,7 +127,6 @@ partial class CollectDumpActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectDumpOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -173,7 +168,6 @@ partial class CollectExceptionsActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectExceptionsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -209,7 +203,6 @@ partial class CollectGCDumpActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectGCDumpOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -241,7 +234,6 @@ partial class CollectLiveMetricsActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLiveMetricsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -317,7 +309,6 @@ partial class CollectLogsActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLogsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -383,7 +374,6 @@ partial class CollectStacksActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectStacksOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -419,7 +409,6 @@ partial class CollectTraceActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectTraceOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -507,7 +496,6 @@ partial class ExecuteActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ExecuteOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -538,7 +526,6 @@ partial class GetEnvironmentVariableActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.GetEnvironmentVariableOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -569,7 +556,6 @@ partial class LoadProfilerActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.LoadProfilerOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -611,7 +597,6 @@ partial class SetEnvironmentVariableActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.SetEnvironmentVariableOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -634,7 +619,6 @@ partial class SetEnvironmentVariableActionDescriptor } namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __CollectionRuleLimitsOptionsValidator__ { /// @@ -643,7 +627,6 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleLimitsOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -686,7 +669,6 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ } namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] internal sealed partial class __TraceEventFilterValidator__ { /// @@ -695,7 +677,6 @@ internal sealed partial class __TraceEventFilterValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.TraceEventFilter options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -736,7 +717,6 @@ partial class CollectionRuleActionOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -771,7 +751,6 @@ partial class CollectionRuleTriggerOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -806,7 +785,6 @@ partial class EventCounterOptions /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -861,7 +839,6 @@ partial class AspNetRequestCountTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestCountOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -903,7 +880,6 @@ partial class AspNetRequestDurationTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestDurationOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -955,7 +931,6 @@ partial class AspNetResponseStatusTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetResponseStatusOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -1009,7 +984,6 @@ partial class CPUUsageTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.CPUUsageOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -1064,7 +1038,6 @@ partial class EventCounterTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -1119,7 +1092,6 @@ partial class EventMeterTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventMeterOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -1184,7 +1156,6 @@ partial class GCHeapSizeTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.GCHeapSizeOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -1239,7 +1210,6 @@ partial class ThreadpoolQueueLengthTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.ThreadpoolQueueLengthOptions options) { global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; @@ -1286,7 +1256,6 @@ partial class ThreadpoolQueueLengthTriggerDescriptor } namespace __OptionValidationStaticInstances { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] file static class __Attributes { internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A1 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute(); @@ -1374,14 +1343,12 @@ file static class __Attributes } namespace __OptionValidationStaticInstances { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] file static class __Validators { } } namespace __OptionValidationGeneratedAttributes { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] file class __SourceGen__MinLengthAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute { @@ -1418,7 +1385,7 @@ public override bool IsValid(object? value) } public override string FormatErrorMessage(string name) => string.Format(global::System.Globalization.CultureInfo.CurrentCulture, ErrorMessageString, name, Length); } - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Options.SourceGeneration", "10.0.12.25812")] + [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] file class __SourceGen__RangeAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute { From 7cf5c0374d2a0e72eafa1c94cfbf00db35f0240e Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 7 Jul 2025 23:06:05 +0000 Subject: [PATCH 12/13] Fix namespaces in dotnet-monitor validators --- src/Tools/dotnet-monitor/Validators.cs | 762 +++++++++++++------------ 1 file changed, 390 insertions(+), 372 deletions(-) diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs index 78de0f901f8..01df2db8232 100644 --- a/src/Tools/dotnet-monitor/Validators.cs +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -1,6 +1,24 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using __OptionValidationStaticInstances; +using Microsoft.Diagnostics.Monitoring.Options; +using Microsoft.Diagnostics.Monitoring.WebApi; +using Microsoft.Diagnostics.Monitoring.WebApi.Models; +using Microsoft.Diagnostics.Monitoring.WebApi.Validation; +using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options; +using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions; +using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers; +using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.Tracing; +using System.Globalization; + // #nullable enable #pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103 @@ -14,24 +32,24 @@ internal sealed partial class __EventMetricsMeterValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsMeter options) + public static ValidateOptionsResult Validate(string? name, EventMetricsMeter options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "EventMetricsMeter.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "MeterName"; context.DisplayName = "EventMetricsMeter.MeterName"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MeterName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + validationAttributes.Add(__Attributes.A2); + if (!Validator.TryValidateValue(options.MeterName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -45,24 +63,24 @@ internal sealed partial class __EventMetricsProviderValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventMetricsProvider options) + public static ValidateOptionsResult Validate(string? name, EventMetricsProvider options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "EventMetricsProvider.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "ProviderName"; context.DisplayName = "EventMetricsProvider.ProviderName"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + validationAttributes.Add(__Attributes.A2); + if (!Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -76,19 +94,19 @@ internal sealed partial class __EventPipeProviderValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Monitoring.WebApi.Models.EventPipeProvider options) + public static ValidateOptionsResult Validate(string? name, EventPipeProvider options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "EventPipeProvider.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "Name"; context.DisplayName = "EventPipeProvider.Name"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + validationAttributes.Add(__Attributes.A2); + if (!Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -97,8 +115,8 @@ internal sealed partial class __EventPipeProviderValidator__ context.DisplayName = "EventPipeProvider.Keywords"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A3); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Keywords, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A3); + if (!Validator.TryValidateValue(options.Keywords, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -107,13 +125,13 @@ internal sealed partial class __EventPipeProviderValidator__ context.DisplayName = "EventPipeProvider.EventLevel"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A4); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.EventLevel, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A4); + if (!Validator.TryValidateValue(options.EventLevel, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -127,18 +145,18 @@ partial class CollectDumpActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectDumpOptions options) + public ValidateOptionsResult Validate(string? name, CollectDumpOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectDumpOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "Type"; context.DisplayName = "CollectDumpOptions.Type"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A5); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A5); + if (!Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -147,14 +165,14 @@ partial class CollectDumpActionDescriptor context.DisplayName = "CollectDumpOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A6); + validationAttributes.Add(__Attributes.A7); + if (!Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -168,28 +186,28 @@ partial class CollectExceptionsActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectExceptionsOptions options) + public ValidateOptionsResult Validate(string? name, CollectExceptionsOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectExceptionsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "Egress"; context.DisplayName = "CollectExceptionsOptions.Egress"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A6); + validationAttributes.Add(__Attributes.A7); + if (!Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "CollectExceptionsOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -203,24 +221,24 @@ partial class CollectGCDumpActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectGCDumpOptions options) + public ValidateOptionsResult Validate(string? name, CollectGCDumpOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectGCDumpOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "Egress"; context.DisplayName = "CollectGCDumpOptions.Egress"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A6); + validationAttributes.Add(__Attributes.A7); + if (!Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -234,13 +252,13 @@ partial class CollectLiveMetricsActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLiveMetricsOptions options) + public ValidateOptionsResult Validate(string? name, CollectLiveMetricsOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectLiveMetricsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(2); if (options.Providers is not null) { @@ -249,7 +267,7 @@ partial class CollectLiveMetricsActionDescriptor { if (o is not null) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.__EventMetricsProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); + (builder ??= new()).AddResult(__EventMetricsProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); } else { @@ -266,7 +284,7 @@ partial class CollectLiveMetricsActionDescriptor { if (o is not null) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.__EventMetricsMeterValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Meters[{count}]" : $"{name}.Meters[{count}]", o)); + (builder ??= new()).AddResult(__EventMetricsMeterValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectLiveMetricsOptions.Meters[{count}]" : $"{name}.Meters[{count}]", o)); } else { @@ -278,8 +296,8 @@ partial class CollectLiveMetricsActionDescriptor context.MemberName = "Duration"; context.DisplayName = "CollectLiveMetricsOptions.Duration"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -288,14 +306,14 @@ partial class CollectLiveMetricsActionDescriptor context.DisplayName = "CollectLiveMetricsOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A6); + validationAttributes.Add(__Attributes.A7); + if (!Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -309,18 +327,18 @@ partial class CollectLogsActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectLogsOptions options) + public ValidateOptionsResult Validate(string? name, CollectLogsOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectLogsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "DefaultLevel"; context.DisplayName = "CollectLogsOptions.DefaultLevel"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A9); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.DefaultLevel, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A9); + if (!Validator.TryValidateValue(options.DefaultLevel, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -329,8 +347,8 @@ partial class CollectLogsActionDescriptor context.DisplayName = "CollectLogsOptions.Duration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -339,9 +357,9 @@ partial class CollectLogsActionDescriptor context.DisplayName = "CollectLogsOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A6); + validationAttributes.Add(__Attributes.A7); + if (!Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -350,17 +368,17 @@ partial class CollectLogsActionDescriptor context.DisplayName = "CollectLogsOptions.Format"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A10); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Format, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A10); + if (!Validator.TryValidateValue(options.Format, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "CollectLogsOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -374,28 +392,28 @@ partial class CollectStacksActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectStacksOptions options) + public ValidateOptionsResult Validate(string? name, CollectStacksOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectStacksOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "Egress"; context.DisplayName = "CollectStacksOptions.Egress"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A6); + validationAttributes.Add(__Attributes.A7); + if (!Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "CollectStacksOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -409,18 +427,18 @@ partial class CollectTraceActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.CollectTraceOptions options) + public ValidateOptionsResult Validate(string? name, CollectTraceOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectTraceOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "Profile"; context.DisplayName = "CollectTraceOptions.Profile"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A11); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Profile, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A11); + if (!Validator.TryValidateValue(options.Profile, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -432,7 +450,7 @@ partial class CollectTraceActionDescriptor { if (o is not null) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.__EventPipeProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectTraceOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); + (builder ??= new()).AddResult(__EventPipeProviderValidator__.Validate(string.IsNullOrEmpty(name) ? $"CollectTraceOptions.Providers[{count}]" : $"{name}.Providers[{count}]", o)); } else { @@ -446,8 +464,8 @@ partial class CollectTraceActionDescriptor context.DisplayName = "CollectTraceOptions.BufferSizeMegabytes"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A12); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.BufferSizeMegabytes, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A12); + if (!Validator.TryValidateValue(options.BufferSizeMegabytes, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -456,8 +474,8 @@ partial class CollectTraceActionDescriptor context.DisplayName = "CollectTraceOptions.Duration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.Duration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -466,23 +484,23 @@ partial class CollectTraceActionDescriptor context.DisplayName = "CollectTraceOptions.Egress"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A6); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A7); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A6); + validationAttributes.Add(__Attributes.A7); + if (!Validator.TryValidateValue(options.Egress, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } if (options.StoppingEvent is not null) { - (builder ??= new()).AddResult(global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.__TraceEventFilterValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectTraceOptions.StoppingEvent" : $"{name}.StoppingEvent", options.StoppingEvent)); + (builder ??= new()).AddResult(__TraceEventFilterValidator__.Validate(string.IsNullOrEmpty(name) ? "CollectTraceOptions.StoppingEvent" : $"{name}.StoppingEvent", options.StoppingEvent)); } context.MemberName = "Validate"; context.DisplayName = "CollectTraceOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -496,23 +514,23 @@ partial class ExecuteActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ExecuteOptions options) + public ValidateOptionsResult Validate(string? name, ExecuteOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "ExecuteOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "Path"; context.DisplayName = "ExecuteOptions.Path"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -526,23 +544,23 @@ partial class GetEnvironmentVariableActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.GetEnvironmentVariableOptions options) + public ValidateOptionsResult Validate(string? name, GetEnvironmentVariableOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "GetEnvironmentVariableOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "Name"; context.DisplayName = "GetEnvironmentVariableOptions.Name"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -556,18 +574,18 @@ partial class LoadProfilerActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.LoadProfilerOptions options) + public ValidateOptionsResult Validate(string? name, LoadProfilerOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "LoadProfilerOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "Path"; context.DisplayName = "LoadProfilerOptions.Path"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.Path, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -576,14 +594,14 @@ partial class LoadProfilerActionDescriptor context.DisplayName = "LoadProfilerOptions.Clsid"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A13); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Clsid, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + validationAttributes.Add(__Attributes.A13); + if (!Validator.TryValidateValue(options.Clsid, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -597,23 +615,23 @@ partial class SetEnvironmentVariableActionDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.SetEnvironmentVariableOptions options) + public ValidateOptionsResult Validate(string? name, SetEnvironmentVariableOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "SetEnvironmentVariableOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "Name"; context.DisplayName = "SetEnvironmentVariableOptions.Name"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.Name, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -627,18 +645,18 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleLimitsOptions options) + public static ValidateOptionsResult Validate(string? name, CollectionRuleLimitsOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleLimitsOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "ActionCount"; context.DisplayName = "CollectionRuleLimitsOptions.ActionCount"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ActionCount, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A14); + if (!Validator.TryValidateValue(options.ActionCount, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -647,8 +665,8 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ context.DisplayName = "CollectionRuleLimitsOptions.ActionCountSlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ActionCountSlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.ActionCountSlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -657,13 +675,13 @@ internal sealed partial class __CollectionRuleLimitsOptionsValidator__ context.DisplayName = "CollectionRuleLimitsOptions.RuleDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A15); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RuleDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A15); + if (!Validator.TryValidateValue(options.RuleDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -677,18 +695,18 @@ internal sealed partial class __TraceEventFilterValidator__ /// The name of the options instance being validated. /// The options instance. /// Validation result. - public static global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.TraceEventFilter options) + public static ValidateOptionsResult Validate(string? name, TraceEventFilter options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "TraceEventFilter.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "ProviderName"; context.DisplayName = "TraceEventFilter.ProviderName"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -697,13 +715,13 @@ internal sealed partial class __TraceEventFilterValidator__ context.DisplayName = "TraceEventFilter.EventName"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.EventName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.EventName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -717,27 +735,27 @@ partial class CollectionRuleActionOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleActionOptions options) + public ValidateOptionsResult Validate(string? name, CollectionRuleActionOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleActionOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "Type"; context.DisplayName = "CollectionRuleActionOptions.Type"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "CollectionRuleActionOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -751,27 +769,27 @@ partial class CollectionRuleTriggerOptionsValidator /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleTriggerOptions options) + public ValidateOptionsResult Validate(string? name, CollectionRuleTriggerOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CollectionRuleTriggerOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, _serviceProvider, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, _serviceProvider, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "Type"; context.DisplayName = "CollectionRuleTriggerOptions.Type"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.Type, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "CollectionRuleTriggerOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -785,18 +803,18 @@ partial class EventCounterOptions /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) + public static ValidateOptionsResult Validate(string? name, EventCounterOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "EventCounterOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "ProviderName"; context.DisplayName = "EventCounterOptions.ProviderName"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -805,8 +823,8 @@ partial class EventCounterOptions context.DisplayName = "EventCounterOptions.CounterName"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.CounterName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.CounterName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -815,17 +833,17 @@ partial class EventCounterOptions context.DisplayName = "EventCounterOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "EventCounterOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -839,19 +857,19 @@ partial class AspNetRequestCountTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestCountOptions options) + public ValidateOptionsResult Validate(string? name, AspNetRequestCountOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "AspNetRequestCountOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "RequestCount"; context.DisplayName = "AspNetRequestCountOptions.RequestCount"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A16); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RequestCount, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A16); + validationAttributes.Add(__Attributes.A14); + if (!Validator.TryValidateValue(options.RequestCount, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -860,13 +878,13 @@ partial class AspNetRequestCountTriggerDescriptor context.DisplayName = "AspNetRequestCountOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -880,19 +898,19 @@ partial class AspNetRequestDurationTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetRequestDurationOptions options) + public ValidateOptionsResult Validate(string? name, AspNetRequestDurationOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "AspNetRequestDurationOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(2); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(2); context.MemberName = "RequestCount"; context.DisplayName = "AspNetRequestDurationOptions.RequestCount"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A16); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RequestCount, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A16); + validationAttributes.Add(__Attributes.A14); + if (!Validator.TryValidateValue(options.RequestCount, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -901,8 +919,8 @@ partial class AspNetRequestDurationTriggerDescriptor context.DisplayName = "AspNetRequestDurationOptions.RequestDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A17); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.RequestDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A17); + if (!Validator.TryValidateValue(options.RequestDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -911,13 +929,13 @@ partial class AspNetRequestDurationTriggerDescriptor context.DisplayName = "AspNetRequestDurationOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -931,20 +949,20 @@ partial class AspNetResponseStatusTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.AspNetResponseStatusOptions options) + public ValidateOptionsResult Validate(string? name, AspNetResponseStatusOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "AspNetResponseStatusOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(3); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(3); context.MemberName = "StatusCodes"; context.DisplayName = "AspNetResponseStatusOptions.StatusCodes"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A2); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A18); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.StatusCodes, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + validationAttributes.Add(__Attributes.A2); + validationAttributes.Add(__Attributes.A18); + if (!Validator.TryValidateValue(options.StatusCodes, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -953,9 +971,9 @@ partial class AspNetResponseStatusTriggerDescriptor context.DisplayName = "AspNetResponseStatusOptions.ResponseCount"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A19); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A14); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ResponseCount, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A19); + validationAttributes.Add(__Attributes.A14); + if (!Validator.TryValidateValue(options.ResponseCount, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -964,13 +982,13 @@ partial class AspNetResponseStatusTriggerDescriptor context.DisplayName = "AspNetResponseStatusOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -984,18 +1002,18 @@ partial class CPUUsageTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.CPUUsageOptions options) + public ValidateOptionsResult Validate(string? name, CPUUsageOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "CPUUsageOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "GreaterThan"; context.DisplayName = "CPUUsageOptions.GreaterThan"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A20); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A20); + if (!Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1004,8 +1022,8 @@ partial class CPUUsageTriggerDescriptor context.DisplayName = "CPUUsageOptions.LessThan"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A20); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A20); + if (!Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1014,17 +1032,17 @@ partial class CPUUsageTriggerDescriptor context.DisplayName = "CPUUsageOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "CPUUsageOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -1038,18 +1056,18 @@ partial class EventCounterTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterOptions options) + public ValidateOptionsResult Validate(string? name, EventCounterOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "EventCounterOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "ProviderName"; context.DisplayName = "EventCounterOptions.ProviderName"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.ProviderName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1058,8 +1076,8 @@ partial class EventCounterTriggerDescriptor context.DisplayName = "EventCounterOptions.CounterName"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.CounterName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.CounterName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1068,17 +1086,17 @@ partial class EventCounterTriggerDescriptor context.DisplayName = "EventCounterOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "EventCounterOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -1092,18 +1110,18 @@ partial class EventMeterTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventMeterOptions options) + public ValidateOptionsResult Validate(string? name, EventMeterOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "EventMeterOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "MeterName"; context.DisplayName = "EventMeterOptions.MeterName"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.MeterName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.MeterName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1112,8 +1130,8 @@ partial class EventMeterTriggerDescriptor context.DisplayName = "EventMeterOptions.InstrumentName"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A1); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.InstrumentName, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A1); + if (!Validator.TryValidateValue(options.InstrumentName, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1122,8 +1140,8 @@ partial class EventMeterTriggerDescriptor context.DisplayName = "EventMeterOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1132,17 +1150,17 @@ partial class EventMeterTriggerDescriptor context.DisplayName = "EventMeterOptions.HistogramPercentile"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A20); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.HistogramPercentile, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A20); + if (!Validator.TryValidateValue(options.HistogramPercentile, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "EventMeterOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -1156,18 +1174,18 @@ partial class GCHeapSizeTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.GCHeapSizeOptions options) + public ValidateOptionsResult Validate(string? name, GCHeapSizeOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "GCHeapSizeOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "GreaterThan"; context.DisplayName = "GCHeapSizeOptions.GreaterThan"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A21); + if (!Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1176,8 +1194,8 @@ partial class GCHeapSizeTriggerDescriptor context.DisplayName = "GCHeapSizeOptions.LessThan"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A21); + if (!Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1186,17 +1204,17 @@ partial class GCHeapSizeTriggerDescriptor context.DisplayName = "GCHeapSizeOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "GCHeapSizeOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } @@ -1210,18 +1228,18 @@ partial class ThreadpoolQueueLengthTriggerDescriptor /// The name of the options instance being validated. /// The options instance. /// Validation result. - public global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Triggers.EventCounterShortcuts.ThreadpoolQueueLengthOptions options) + public ValidateOptionsResult Validate(string? name, ThreadpoolQueueLengthOptions options) { - global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null; + ValidateOptionsResultBuilder? builder = null; string displayName = string.IsNullOrEmpty(name) ? "ThreadpoolQueueLengthOptions.Validate" : $"{name}.Validate"; - var context = new global::System.ComponentModel.DataAnnotations.ValidationContext(options, displayName, null, null); - var validationResults = new global::System.Collections.Generic.List(); - var validationAttributes = new global::System.Collections.Generic.List(1); + var context = new ValidationContext(options, displayName, null, null); + var validationResults = new List(); + var validationAttributes = new List(1); context.MemberName = "GreaterThan"; context.DisplayName = "ThreadpoolQueueLengthOptions.GreaterThan"; - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A21); + if (!Validator.TryValidateValue(options.GreaterThan, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1230,8 +1248,8 @@ partial class ThreadpoolQueueLengthTriggerDescriptor context.DisplayName = "ThreadpoolQueueLengthOptions.LessThan"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A21); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A21); + if (!Validator.TryValidateValue(options.LessThan, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } @@ -1240,96 +1258,96 @@ partial class ThreadpoolQueueLengthTriggerDescriptor context.DisplayName = "ThreadpoolQueueLengthOptions.SlidingWindowDuration"; validationResults.Clear(); validationAttributes.Clear(); - validationAttributes.Add(global::__OptionValidationStaticInstances.__Attributes.A8); - if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) + validationAttributes.Add(__Attributes.A8); + if (!Validator.TryValidateValue(options.SlidingWindowDuration, context, validationResults, validationAttributes)) { (builder ??= new()).AddResults(validationResults); } context.MemberName = "Validate"; context.DisplayName = "ThreadpoolQueueLengthOptions.Validate"; - (builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context)); + (builder ??= new()).AddResults(((IValidatableObject)options).Validate(context)); - return builder is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : builder.Build(); + return builder is null ? ValidateOptionsResult.Success : builder.Build(); } } } namespace __OptionValidationStaticInstances { - file static class __Attributes + static file class __Attributes { - internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A1 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute(); + internal static readonly RequiredAttribute A1 = new RequiredAttribute(); internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__MinLengthAttribute A2 = new __OptionValidationGeneratedAttributes.__SourceGen__MinLengthAttribute( (int)1); - internal static readonly global::Microsoft.Diagnostics.Monitoring.WebApi.Validation.IntegerOrHexStringAttribute A3 = new global::Microsoft.Diagnostics.Monitoring.WebApi.Validation.IntegerOrHexStringAttribute(); + internal static readonly IntegerOrHexStringAttribute A3 = new IntegerOrHexStringAttribute(); - internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A4 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( - typeof(global::System.Diagnostics.Tracing.EventLevel)); + internal static readonly EnumDataTypeAttribute A4 = new EnumDataTypeAttribute( + typeof(EventLevel)); - internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A5 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( - typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.DumpType)); + internal static readonly EnumDataTypeAttribute A5 = new EnumDataTypeAttribute( + typeof(DumpType)); - internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A6 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute() + internal static readonly RequiredAttribute A6 = new RequiredAttribute() { ErrorMessageResourceName = "ErrorMessage_NoDefaultEgressProvider", - ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + ErrorMessageResourceType = typeof(OptionsDisplayStrings) }; - internal static readonly global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ValidateEgressProviderAttribute A7 = new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.ValidateEgressProviderAttribute(); + internal static readonly ValidateEgressProviderAttribute A7 = new ValidateEgressProviderAttribute(); internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A8 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( - typeof(global::System.TimeSpan), + typeof(TimeSpan), "00:00:01", "1.00:00:00"); - internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A9 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( - typeof(global::Microsoft.Extensions.Logging.LogLevel)); + internal static readonly EnumDataTypeAttribute A9 = new EnumDataTypeAttribute( + typeof(LogLevel)); - internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A10 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( - typeof(global::Microsoft.Diagnostics.Monitoring.Options.LogFormat)); + internal static readonly EnumDataTypeAttribute A10 = new EnumDataTypeAttribute( + typeof(LogFormat)); - internal static readonly global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute A11 = new global::System.ComponentModel.DataAnnotations.EnumDataTypeAttribute( - typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.Models.TraceProfile)); + internal static readonly EnumDataTypeAttribute A11 = new EnumDataTypeAttribute( + typeof(TraceProfile)); internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A12 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( (int)1, (int)1024); - internal static readonly global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.RequiredGuidAttribute A13 = new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions.RequiredGuidAttribute(); + internal static readonly RequiredGuidAttribute A13 = new RequiredGuidAttribute(); internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A14 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( (int)1, (int)2147483647); internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A15 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( - typeof(global::System.TimeSpan), + typeof(TimeSpan), "00:00:01", "365.00:00:00"); - internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A16 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute() + internal static readonly RequiredAttribute A16 = new RequiredAttribute() { ErrorMessageResourceName = "ErrorMessage_NoDefaultRequestCount", - ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + ErrorMessageResourceType = typeof(OptionsDisplayStrings) }; internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A17 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( - typeof(global::System.TimeSpan), + typeof(TimeSpan), "00:00:00", "01:00:00"); - internal static readonly global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.RegularExpressionsAttribute A18 = new global::Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.RegularExpressionsAttribute( + internal static readonly RegularExpressionsAttribute A18 = new RegularExpressionsAttribute( "[1-5][0-9]{2}(-[1-5][0-9]{2})?") { ErrorMessageResourceName = "ErrorMessage_StatusCodesRegularExpressionDoesNotMatch", - ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + ErrorMessageResourceType = typeof(OptionsDisplayStrings) }; - internal static readonly global::System.ComponentModel.DataAnnotations.RequiredAttribute A19 = new global::System.ComponentModel.DataAnnotations.RequiredAttribute() + internal static readonly RequiredAttribute A19 = new RequiredAttribute() { ErrorMessageResourceName = "ErrorMessage_NoDefaultResponseCount", - ErrorMessageResourceType = typeof(global::Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayStrings) + ErrorMessageResourceType = typeof(OptionsDisplayStrings) }; internal static readonly __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute A20 = new __OptionValidationGeneratedAttributes.__SourceGen__RangeAttribute( @@ -1343,14 +1361,14 @@ file static class __Attributes } namespace __OptionValidationStaticInstances { - file static class __Validators + static class __Validators { } } namespace __OptionValidationGeneratedAttributes { - [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] - file class __SourceGen__MinLengthAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + file class __SourceGen__MinLengthAttribute : ValidationAttribute { private static string DefaultErrorMessageString => "The field {0} must be a string or array type with a minimum length of '{1}'."; @@ -1360,7 +1378,7 @@ public override bool IsValid(object? value) { if (Length < -1) { - throw new global::System.InvalidOperationException("MinLengthAttribute must have a Length value that is zero or greater."); + throw new InvalidOperationException("MinLengthAttribute must have a Length value that is zero or greater."); } if (value == null) { @@ -1372,22 +1390,22 @@ public override bool IsValid(object? value) { length = stringValue.Length; } - else if (value is System.Collections.ICollection collectionValue) + else if (value is ICollection collectionValue) { length = collectionValue.Count; } else { - throw new global::System.InvalidCastException($"The field of type {value.GetType()} must be a string, array, or ICollection type."); + throw new InvalidCastException($"The field of type {value.GetType()} must be a string, array, or ICollection type."); } return length >= Length; } - public override string FormatErrorMessage(string name) => string.Format(global::System.Globalization.CultureInfo.CurrentCulture, ErrorMessageString, name, Length); + public override string FormatErrorMessage(string name) => string.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, Length); } - [global::System.AttributeUsage(global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Parameter, AllowMultiple = false)] - file class __SourceGen__RangeAttribute : global::System.ComponentModel.DataAnnotations.ValidationAttribute + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + file class __SourceGen__RangeAttribute : ValidationAttribute { public __SourceGen__RangeAttribute(int minimum, int maximum) : base() { @@ -1401,7 +1419,7 @@ public __SourceGen__RangeAttribute(double minimum, double maximum) : base() Maximum = maximum; OperandType = typeof(double); } - public __SourceGen__RangeAttribute(global::System.Type type, string minimum, string maximum) : base() + public __SourceGen__RangeAttribute(Type type, string minimum, string maximum) : base() { OperandType = type; _needToConvertMinMax = true; @@ -1412,11 +1430,11 @@ public __SourceGen__RangeAttribute(global::System.Type type, string minimum, str public object Maximum { get; private set; } public bool MinimumIsExclusive { get; set; } public bool MaximumIsExclusive { get; set; } - public global::System.Type OperandType { get; } + public Type OperandType { get; } public bool ParseLimitsInInvariantCulture { get; set; } public bool ConvertValueInInvariantCulture { get; set; } public override string FormatErrorMessage(string name) => - string.Format(global::System.Globalization.CultureInfo.CurrentCulture, GetValidationErrorMessage(), name, Minimum, Maximum); + string.Format(CultureInfo.CurrentCulture, GetValidationErrorMessage(), name, Minimum, Maximum); private readonly bool _needToConvertMinMax; private volatile bool _initialized; private readonly object _lock = new(); @@ -1432,35 +1450,35 @@ public override bool IsValid(object? value) { if (Minimum is null || Maximum is null) { - throw new global::System.InvalidOperationException(MinMaxError); + throw new InvalidOperationException(MinMaxError); } if (_needToConvertMinMax) { - System.Globalization.CultureInfo culture = ParseLimitsInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; - if (OperandType == typeof(global::System.TimeSpan)) + CultureInfo culture = ParseLimitsInInvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture; + if (OperandType == typeof(TimeSpan)) { - if (!global::System.TimeSpan.TryParse((string)Minimum, culture, out global::System.TimeSpan timeSpanMinimum) || - !global::System.TimeSpan.TryParse((string)Maximum, culture, out global::System.TimeSpan timeSpanMaximum)) + if (!TimeSpan.TryParse((string)Minimum, culture, out TimeSpan timeSpanMinimum) || + !TimeSpan.TryParse((string)Maximum, culture, out TimeSpan timeSpanMaximum)) { - throw new global::System.InvalidOperationException(MinMaxError); + throw new InvalidOperationException(MinMaxError); } Minimum = timeSpanMinimum; Maximum = timeSpanMaximum; } else { - Minimum = ConvertValue(Minimum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); - Maximum = ConvertValue(Maximum, culture) ?? throw new global::System.InvalidOperationException(MinMaxError); + Minimum = ConvertValue(Minimum, culture) ?? throw new InvalidOperationException(MinMaxError); + Maximum = ConvertValue(Maximum, culture) ?? throw new InvalidOperationException(MinMaxError); } } - int cmp = ((global::System.IComparable)Minimum).CompareTo((global::System.IComparable)Maximum); + int cmp = ((IComparable)Minimum).CompareTo((IComparable)Maximum); if (cmp > 0) { - throw new global::System.InvalidOperationException("The maximum value '{Maximum}' must be greater than or equal to the minimum value '{Minimum}'."); + throw new InvalidOperationException("The maximum value '{Maximum}' must be greater than or equal to the minimum value '{Minimum}'."); } else if (cmp == 0 && (MinimumIsExclusive || MaximumIsExclusive)) { - throw new global::System.InvalidOperationException("Cannot use exclusive bounds when the maximum value is equal to the minimum value."); + throw new InvalidOperationException("Cannot use exclusive bounds when the maximum value is equal to the minimum value."); } _initialized = true; } @@ -1472,18 +1490,18 @@ public override bool IsValid(object? value) return true; } - System.Globalization.CultureInfo formatProvider = ConvertValueInInvariantCulture ? global::System.Globalization.CultureInfo.InvariantCulture : global::System.Globalization.CultureInfo.CurrentCulture; + CultureInfo formatProvider = ConvertValueInInvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture; object? convertedValue; - if (OperandType == typeof(global::System.TimeSpan)) + if (OperandType == typeof(TimeSpan)) { - if (value is global::System.TimeSpan) + if (value is TimeSpan) { convertedValue = value; } else if (value is string) { - if (!global::System.TimeSpan.TryParse((string)value, formatProvider, out global::System.TimeSpan timeSpanValue)) + if (!TimeSpan.TryParse((string)value, formatProvider, out TimeSpan timeSpanValue)) { return false; } @@ -1491,7 +1509,7 @@ public override bool IsValid(object? value) } else { - throw new global::System.InvalidOperationException($"A value type {value.GetType()} that is not a TimeSpan or a string has been given. This might indicate a problem with the source generator."); + throw new InvalidOperationException($"A value type {value.GetType()} that is not a TimeSpan or a string has been given. This might indicate a problem with the source generator."); } } else @@ -1500,14 +1518,14 @@ public override bool IsValid(object? value) { convertedValue = ConvertValue(value, formatProvider); } - catch (global::System.Exception e) when (e is global::System.FormatException or global::System.InvalidCastException or global::System.NotSupportedException) + catch (Exception e) when (e is FormatException or InvalidCastException or NotSupportedException) { return false; } } - var min = (global::System.IComparable)Minimum; - var max = (global::System.IComparable)Maximum; + var min = (IComparable)Minimum; + var max = (IComparable)Maximum; return (MinimumIsExclusive ? min.CompareTo(convertedValue) < 0 : min.CompareTo(convertedValue) <= 0) && @@ -1523,15 +1541,15 @@ private string GetValidationErrorMessage() (true, true) => "The field {0} must be between {1} exclusive and {2} exclusive.", }; } - private object? ConvertValue(object? value, System.Globalization.CultureInfo formatProvider) + private object? ConvertValue(object? value, CultureInfo formatProvider) { if (value is string stringValue) { - value = global::System.Convert.ChangeType(stringValue, OperandType, formatProvider); + value = Convert.ChangeType(stringValue, OperandType, formatProvider); } else { - value = global::System.Convert.ChangeType(value, OperandType, formatProvider); + value = Convert.ChangeType(value, OperandType, formatProvider); } return value; } From f0e898487299b35c326187f87b51e385c341e23b Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 10 Jul 2025 16:57:08 +0000 Subject: [PATCH 13/13] Move validators out of Microsoft.Diagnostics.Monitoring.Options Because they rely on .NET10+ ValidationContext ctor --- .../GlobalCounterOptions.cs | 16 ---------------- ...ileSystemEgressProviderOptionsValidator.cs | 0 .../GlobalCounterOptionsValidator.cs | 19 +++++++++++++++++++ .../GlobalProviderOptionsValidator.cs | 12 ++++++++++++ .../MetricsOptionsValidator.cs | 0 .../OptionsValidators/OptionsValidators.cs} | 8 +------- src/Tools/dotnet-monitor/Validators.cs | 6 ------ 7 files changed, 32 insertions(+), 29 deletions(-) rename src/{Microsoft.Diagnostics.Monitoring.Options => Tools/dotnet-monitor/OptionsValidators}/FileSystemEgressProviderOptionsValidator.cs (100%) create mode 100644 src/Tools/dotnet-monitor/OptionsValidators/GlobalCounterOptionsValidator.cs create mode 100644 src/Tools/dotnet-monitor/OptionsValidators/GlobalProviderOptionsValidator.cs rename src/{Microsoft.Diagnostics.Monitoring.Options => Tools/dotnet-monitor/OptionsValidators}/MetricsOptionsValidator.cs (100%) rename src/{Microsoft.Diagnostics.Monitoring.Options/Validators.cs => Tools/dotnet-monitor/OptionsValidators/OptionsValidators.cs} (99%) diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs b/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs index 5c213a302be..fc396a75c70 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/GlobalCounterOptions.cs @@ -50,11 +50,6 @@ public class GlobalProviderOptions public float? IntervalSeconds { get; set; } } - [OptionsValidator] - partial class GlobalProviderOptionsValidator : IValidateOptions - { - } - partial class GlobalCounterOptions : IValidatableObject { public IEnumerable Validate(ValidationContext validationContext) @@ -80,17 +75,6 @@ public IEnumerable Validate(ValidationContext validationContex } } - [OptionsValidator] - partial class GlobalCounterOptionsValidator : IValidateOptions - { - private readonly IServiceProvider _serviceProvider; - - public GlobalCounterOptionsValidator(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - } - } - internal static class GlobalCounterOptionsExtensions { public static float GetIntervalSeconds(this GlobalCounterOptions options) => diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptionsValidator.cs b/src/Tools/dotnet-monitor/OptionsValidators/FileSystemEgressProviderOptionsValidator.cs similarity index 100% rename from src/Microsoft.Diagnostics.Monitoring.Options/FileSystemEgressProviderOptionsValidator.cs rename to src/Tools/dotnet-monitor/OptionsValidators/FileSystemEgressProviderOptionsValidator.cs diff --git a/src/Tools/dotnet-monitor/OptionsValidators/GlobalCounterOptionsValidator.cs b/src/Tools/dotnet-monitor/OptionsValidators/GlobalCounterOptionsValidator.cs new file mode 100644 index 00000000000..c63efba34c4 --- /dev/null +++ b/src/Tools/dotnet-monitor/OptionsValidators/GlobalCounterOptionsValidator.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using Microsoft.Extensions.Options; + +namespace Microsoft.Diagnostics.Monitoring.WebApi +{ + [OptionsValidator] + partial class GlobalCounterOptionsValidator : IValidateOptions + { + private readonly IServiceProvider _serviceProvider; + + public GlobalCounterOptionsValidator(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + } +} diff --git a/src/Tools/dotnet-monitor/OptionsValidators/GlobalProviderOptionsValidator.cs b/src/Tools/dotnet-monitor/OptionsValidators/GlobalProviderOptionsValidator.cs new file mode 100644 index 00000000000..62ab521b8de --- /dev/null +++ b/src/Tools/dotnet-monitor/OptionsValidators/GlobalProviderOptionsValidator.cs @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.Extensions.Options; + +namespace Microsoft.Diagnostics.Monitoring.WebApi +{ + [OptionsValidator] + partial class GlobalProviderOptionsValidator : IValidateOptions + { + } +} diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptionsValidator.cs b/src/Tools/dotnet-monitor/OptionsValidators/MetricsOptionsValidator.cs similarity index 100% rename from src/Microsoft.Diagnostics.Monitoring.Options/MetricsOptionsValidator.cs rename to src/Tools/dotnet-monitor/OptionsValidators/MetricsOptionsValidator.cs diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs b/src/Tools/dotnet-monitor/OptionsValidators/OptionsValidators.cs similarity index 99% rename from src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs rename to src/Tools/dotnet-monitor/OptionsValidators/OptionsValidators.cs index ec05d25fa75..390de3286c9 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/Validators.cs +++ b/src/Tools/dotnet-monitor/OptionsValidators/OptionsValidators.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Extensions.Options; @@ -226,12 +226,6 @@ static class __Attributes (int)2147483647); } } -namespace __OptionValidationStaticInstances -{ - static class __Validators - { - } -} namespace __OptionValidationGeneratedAttributes { [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] diff --git a/src/Tools/dotnet-monitor/Validators.cs b/src/Tools/dotnet-monitor/Validators.cs index 01df2db8232..dbc81ece981 100644 --- a/src/Tools/dotnet-monitor/Validators.cs +++ b/src/Tools/dotnet-monitor/Validators.cs @@ -1359,12 +1359,6 @@ static file class __Attributes (double)1.7976931348623157E+308); } } -namespace __OptionValidationStaticInstances -{ - static class __Validators - { - } -} namespace __OptionValidationGeneratedAttributes { [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]