Skip to content

Commit

Permalink
Enable nullable context for options
Browse files Browse the repository at this point in the history
  • Loading branch information
schmittjoseph committed Jul 1, 2024
1 parent c82a161 commit 4e1979a
Show file tree
Hide file tree
Showing 36 changed files with 120 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Process(SchemaProcessorContext context)
{
if (null != property.GetCustomAttribute<ExperimentalAttribute>())
{
string description = context.Schema.Properties[property.Name].Description;
string? description = context.Schema.Properties[property.Name].Description;
if (string.IsNullOrEmpty(description))
{
description = ExperimentalPrefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<TargetFrameworks>$(SchemaTargetFramework)</TargetFrameworks>
<DefineConstants>$(DefineConstants);SCHEMAGEN</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class ConsoleFormatterOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ConsoleFormatterOptions_TimestampFormat))]
[DefaultValue(null)]
public string TimestampFormat { get; set; }
public string? TimestampFormat { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ internal sealed class ConsoleLoggerOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ConsoleLoggerOptions_FormatterOptions))]
public object FormatterOptions { get; set; }
public object? FormatterOptions { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ConsoleLoggerOptions_LogLevel))]
public IDictionary<string, LogLevel?> LogLevel { get; set; }
public IDictionary<string, LogLevel?>? LogLevel { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class JsonConsoleFormatterOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ConsoleFormatterOptions_TimestampFormat))]
[DefaultValue(null)]
public string TimestampFormat { get; set; }
public string? TimestampFormat { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ internal sealed class LogLevelOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_LogLevelOptions_LogLevel))]
public IDictionary<string, LogLevel?> LogLevel { get; set; }
public IDictionary<string, LogLevel?>? LogLevel { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ internal sealed class LoggingOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_LoggingOptions_LogLevel))]
public IDictionary<string, LogLevel?> LogLevel { get; set; }
public IDictionary<string, LogLevel?>? LogLevel { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_LoggingOptions_Console))]
public ConsoleLoggerOptions Console { get; set; }
public ConsoleLoggerOptions? Console { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_LoggingOptions_EventLog))]
public LogLevelOptions EventLog { get; set; }
public LogLevelOptions? EventLog { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_LoggingOptions_Debug))]
public LogLevelOptions Debug { get; set; }
public LogLevelOptions? Debug { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_LoggingOptions_EventSource))]
public LogLevelOptions EventSource { get; set; }
public LogLevelOptions? EventSource { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Microsoft.Diagnostics.Tools.Monitor
{
internal partial class RootOptions
{
public LoggingOptions Logging { get; set; }
public LoggingOptions? Logging { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal sealed class SimpleConsoleFormatterOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ConsoleFormatterOptions_TimestampFormat))]
[DefaultValue(null)]
public string TimestampFormat { get; set; }
public string? TimestampFormat { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ private static JsonSchemaProperty AddDiscriminatedSubSchema(
string discriminatingPropertyName,
string discriminatingPropertyValue,
string discriminatedPropertyName,
JsonSchema subSchema = null)
JsonSchema? subSchema = null)
{
if (null == subSchema)
{
subSchema = new JsonSchema();
}

JsonSchemaProperty discriminatingProperty = new JsonSchemaProperty();
discriminatingProperty.ExtensionData = new Dictionary<string, object>();
discriminatingProperty.ExtensionData = new Dictionary<string, object?>();
discriminatingProperty.ExtensionData.Add("const", discriminatingPropertyValue);

subSchema.Properties.Add(discriminatingPropertyName, discriminatingProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ internal sealed partial record class CollectDumpOptions : BaseRecordOptions, IEg
#if !UNITTEST && !SCHEMAGEN
[ValidateEgressProvider]
#endif
public string Egress { get; set; }
public string Egress { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.Options;
using Microsoft.Diagnostics.Monitoring.WebApi;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleDefaultsInterfaces;
Expand All @@ -25,7 +27,7 @@ internal sealed partial record class CollectExceptionsOptions : BaseRecordOption
#if !UNITTEST && !SCHEMAGEN
[ValidateEgressProvider]
#endif
public string Egress { get; set; }
public string Egress { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand All @@ -36,6 +38,6 @@ internal sealed partial record class CollectExceptionsOptions : BaseRecordOption
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectExceptionsOptions_Filters))]
public ExceptionsConfiguration Filters { get; set; }
public ExceptionsConfiguration? Filters { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ internal sealed partial record class CollectGCDumpOptions : BaseRecordOptions, I
#if !UNITTEST && !SCHEMAGEN
[ValidateEgressProvider]
#endif
public string Egress { get; set; }
public string Egress { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.WebApi;
using Microsoft.Diagnostics.Monitoring.WebApi.Models;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleDefaultsInterfaces;
Expand Down Expand Up @@ -29,12 +31,12 @@ internal sealed partial record class CollectLiveMetricsOptions : BaseRecordOptio
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectLiveMetricsOptions_Providers))]
public EventMetricsProvider[] Providers { get; set; }
public EventMetricsProvider[]? Providers { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectLiveMetricsOptions_Meters))]
public EventMetricsMeter[] Meters { get; set; }
public EventMetricsMeter[]? Meters { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand All @@ -52,6 +54,6 @@ internal sealed partial record class CollectLiveMetricsOptions : BaseRecordOptio
#if !UNITTEST && !SCHEMAGEN
[ValidateEgressProvider]
#endif
public string Egress { get; set; }
public string Egress { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.Options;
using Microsoft.Diagnostics.Monitoring.WebApi;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleDefaultsInterfaces;
Expand Down Expand Up @@ -32,7 +34,7 @@ internal sealed partial record class CollectLogsOptions : BaseRecordOptions, IEg
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectLogsOptions_FilterSpecs))]
public Dictionary<string, LogLevel?> FilterSpecs { get; set; }
public Dictionary<string, LogLevel?>? FilterSpecs { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand All @@ -56,7 +58,7 @@ internal sealed partial record class CollectLogsOptions : BaseRecordOptions, IEg
#if !UNITTEST && !SCHEMAGEN
[ValidateEgressProvider]
#endif
public string Egress { get; set; }
public string Egress { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal sealed partial record class CollectStacksOptions : BaseRecordOptions, I
#if !UNITTEST && !SCHEMAGEN
[ValidateEgressProvider]
#endif
public string Egress { get; set; }
public string Egress { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.WebApi;
using Microsoft.Diagnostics.Monitoring.WebApi.Models;
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.CollectionRuleDefaultsInterfaces;
Expand Down Expand Up @@ -30,7 +32,7 @@ internal sealed partial record class CollectTraceOptions : BaseRecordOptions, IE
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectTraceOptions_Providers))]
public List<EventPipeProvider> Providers { get; set; }
public List<EventPipeProvider>? Providers { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down Expand Up @@ -61,11 +63,11 @@ internal sealed partial record class CollectTraceOptions : BaseRecordOptions, IE
#if !UNITTEST && !SCHEMAGEN
[ValidateEgressProvider]
#endif
public string Egress { get; set; }
public string Egress { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectTraceOptions_StoppingEvent))]
public TraceEventFilter StoppingEvent { get; set; }
public TraceEventFilter? StoppingEvent { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.WebApi;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
Expand All @@ -21,13 +23,13 @@ internal sealed record class ExecuteOptions : BaseRecordOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ExecuteOptions_Path))]
[Required]
public string Path { get; set; }
public string Path { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ExecuteOptions_Arguments))]
[ActionOptionsDependencyProperty]
public string Arguments { get; set; }
public string? Arguments { get; set; }

[DefaultValue(ExecuteOptionsDefaults.IgnoreExitCode)]
public bool? IgnoreExitCode { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ internal sealed record class GetEnvironmentVariableOptions : BaseRecordOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_GetEnvironmentVariableOptions_Name))]
[Required]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal sealed record class LoadProfilerOptions : BaseRecordOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_LoadProfilerOptions_Path))]
[Required]
public string Path { get; set; }
public string Path { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.WebApi;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
Expand All @@ -20,11 +22,11 @@ internal sealed record class SetEnvironmentVariableOptions : BaseRecordOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_SetEnvironmentVariableOptions_Name))]
[Required]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_SetEnvironmentVariableOptions_Value))]
public string Value { get; set; }
public string? Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.WebApi;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
Expand All @@ -21,17 +23,17 @@ internal sealed record class TraceEventFilter : BaseRecordOptions
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_TraceEventFilter_ProviderName))]
[Required]
public string ProviderName { get; set; }
public string ProviderName { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_TraceEventFilter_EventName))]
[Required]
public string EventName { get; set; }
public string EventName { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_TraceEventFilter_PayloadFilter))]
public IDictionary<string, string> PayloadFilter { get; set; }
public IDictionary<string, string>? PayloadFilter { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Diagnostics.Monitoring.WebApi;
using System.ComponentModel.DataAnnotations;

Expand All @@ -11,6 +13,6 @@ internal sealed class CollectionRuleActionDefaultsOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectionRuleActionDefaultsOptions_Egress))]
public string Egress { get; set; }
public string? Egress { get; set; }
}
}
Loading

0 comments on commit 4e1979a

Please sign in to comment.