Skip to content

Commit c378af0

Browse files
authored
Re-enable IDE0032 (#6866)
1 parent dbc92f8 commit c378af0

File tree

34 files changed

+166
-341
lines changed

34 files changed

+166
-341
lines changed

src/Libraries/.editorconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ dotnet_style_null_propagation = true
20122012
# Title : Use auto property
20132013
# Category : Style
20142014
# Help Link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0032
2015-
dotnet_diagnostic.IDE0032.severity = silent # https://github.com/dotnet/extensions/issues/6864 tracks re-enabling this
2015+
dotnet_diagnostic.IDE0032.severity = warning
20162016
dotnet_style_prefer_auto_properties = true
20172017

20182018
# Title : Use explicitly provided tuple name
@@ -5889,7 +5889,7 @@ dotnet_diagnostic.SA1414.severity = warning
58895889
# Title : Braces for multi-line statements should not share line
58905890
# Category : StyleCop.CSharp.LayoutRules
58915891
# Help Link: https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1500.md
5892-
dotnet_diagnostic.SA1500.severity = warning
5892+
dotnet_diagnostic.SA1500.severity = suggestion # rule does not work well with field-based property initializers
58935893

58945894
# Title : Statement should not be on a single line
58955895
# Category : StyleCop.CSharp.LayoutRules
@@ -5957,7 +5957,7 @@ dotnet_diagnostic.SA1512.severity = none
59575957
# Title : Closing brace should be followed by blank line
59585958
# Category : StyleCop.CSharp.LayoutRules
59595959
# Help Link: https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1513.md
5960-
dotnet_diagnostic.SA1513.severity = warning
5960+
dotnet_diagnostic.SA1513.severity = suggestion # rule does not work well with field-based property initializers
59615961

59625962
# Title : Element documentation header should be preceded by blank line
59635963
# Category : StyleCop.CSharp.LayoutRules

src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatFinishReason.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ namespace Microsoft.Extensions.AI;
1414
[JsonConverter(typeof(Converter))]
1515
public readonly struct ChatFinishReason : IEquatable<ChatFinishReason>
1616
{
17-
/// <summary>The finish reason value. If <see langword="null"/> because `default(ChatFinishReason)` was used, the instance will behave like <see cref="Stop"/>.</summary>
18-
private readonly string? _value;
19-
2017
/// <summary>Initializes a new instance of the <see cref="ChatFinishReason"/> struct with a string that describes the reason.</summary>
2118
/// <param name="value">The reason value.</param>
2219
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
2320
/// <exception cref="ArgumentException"><paramref name="value"/> is empty or composed entirely of whitespace.</exception>
2421
[JsonConstructor]
2522
public ChatFinishReason(string value)
2623
{
27-
_value = Throw.IfNullOrWhitespace(value);
24+
Value = Throw.IfNullOrWhitespace(value);
2825
}
2926

3027
/// <summary>Gets the finish reason value.</summary>
31-
public string Value => _value ?? Stop.Value;
28+
public string Value => field ?? Stop.Value;
3229

3330
/// <inheritdoc />
3431
public override bool Equals([NotNullWhen(true)] object? obj) => obj is ChatFinishReason other && Equals(other);

src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseUpdate.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public class ChatResponseUpdate
3535
/// <summary>The response update content items.</summary>
3636
private IList<AIContent>? _contents;
3737

38-
/// <summary>The name of the author of the update.</summary>
39-
private string? _authorName;
40-
4138
/// <summary>Initializes a new instance of the <see cref="ChatResponseUpdate"/> class.</summary>
4239
[JsonConstructor]
4340
public ChatResponseUpdate()
@@ -64,8 +61,8 @@ public ChatResponseUpdate(ChatRole? role, IList<AIContent>? contents)
6461
/// <summary>Gets or sets the name of the author of the response update.</summary>
6562
public string? AuthorName
6663
{
67-
get => _authorName;
68-
set => _authorName = string.IsNullOrWhiteSpace(value) ? null : value;
64+
get;
65+
set => field = string.IsNullOrWhiteSpace(value) ? null : value;
6966
}
7067

7168
/// <summary>Gets or sets the role of the author of the response update.</summary>

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/DataContent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Text.Json.Serialization;
1616
using Microsoft.Shared.Diagnostics;
1717

18+
#pragma warning disable IDE0032 // Use auto property
1819
#pragma warning disable CA1307 // Specify StringComparison for clarity
1920

2021
namespace Microsoft.Extensions.AI;

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ErrorContent.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@ namespace Microsoft.Extensions.AI;
1414
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1515
public class ErrorContent : AIContent
1616
{
17-
/// <summary>The error message.</summary>
18-
private string? _message;
19-
2017
/// <summary>Initializes a new instance of the <see cref="ErrorContent"/> class with the specified error message.</summary>
2118
/// <param name="message">The error message to store in this content.</param>
2219
public ErrorContent(string? message)
2320
{
24-
_message = message;
21+
Message = message;
2522
}
2623

2724
/// <summary>Gets or sets the error message.</summary>
2825
[AllowNull]
2926
public string Message
3027
{
31-
get => _message ?? string.Empty;
32-
set => _message = value;
28+
get => field ?? string.Empty;
29+
set;
3330
}
3431

3532
/// <summary>Gets or sets an error code associated with the error.</summary>

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/TextContent.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ namespace Microsoft.Extensions.AI;
1212
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1313
public sealed class TextContent : AIContent
1414
{
15-
private string? _text;
16-
1715
/// <summary>
1816
/// Initializes a new instance of the <see cref="TextContent"/> class.
1917
/// </summary>
2018
/// <param name="text">The text content.</param>
2119
public TextContent(string? text)
2220
{
23-
_text = text;
21+
Text = text;
2422
}
2523

2624
/// <summary>
@@ -29,8 +27,8 @@ public TextContent(string? text)
2927
[AllowNull]
3028
public string Text
3129
{
32-
get => _text ?? string.Empty;
33-
set => _text = value;
30+
get => field ?? string.Empty;
31+
set;
3432
}
3533

3634
/// <inheritdoc/>

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/TextReasoningContent.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ namespace Microsoft.Extensions.AI;
1717
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1818
public sealed class TextReasoningContent : AIContent
1919
{
20-
private string? _text;
21-
2220
/// <summary>
2321
/// Initializes a new instance of the <see cref="TextReasoningContent"/> class.
2422
/// </summary>
2523
/// <param name="text">The text reasoning content.</param>
2624
public TextReasoningContent(string? text)
2725
{
28-
_text = text;
26+
Text = text;
2927
}
3028

3129
/// <summary>
@@ -34,8 +32,8 @@ public TextReasoningContent(string? text)
3432
[AllowNull]
3533
public string Text
3634
{
37-
get => _text ?? string.Empty;
38-
set => _text = value;
35+
get => field ?? string.Empty;
36+
set;
3937
}
4038

4139
/// <summary>Gets or sets an optional opaque blob of data associated with this reasoning content.</summary>

src/Libraries/Microsoft.Extensions.AI.Abstractions/Embeddings/EmbeddingGenerationOptions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ namespace Microsoft.Extensions.AI;
1010
/// <summary>Represents the options for an embedding generation request.</summary>
1111
public class EmbeddingGenerationOptions
1212
{
13-
private int? _dimensions;
14-
1513
/// <summary>Gets or sets the number of dimensions requested in the embedding.</summary>
1614
public int? Dimensions
1715
{
18-
get => _dimensions;
16+
get;
1917
set
2018
{
2119
if (value is not null)
2220
{
2321
_ = Throw.IfLessThan(value.Value, 1, nameof(value));
2422
}
2523

26-
_dimensions = value;
24+
field = value;
2725
}
2826
}
2927

src/Libraries/Microsoft.Extensions.AI.Abstractions/Image/ImageGenerationResponse.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ namespace Microsoft.Extensions.AI;
1111
[Experimental("MEAI001")]
1212
public class ImageGenerationResponse
1313
{
14-
/// <summary>The content items in the generated text response.</summary>
15-
private IList<AIContent>? _contents;
16-
1714
/// <summary>Initializes a new instance of the <see cref="ImageGenerationResponse"/> class.</summary>
1815
[JsonConstructor]
1916
public ImageGenerationResponse()
@@ -24,7 +21,7 @@ public ImageGenerationResponse()
2421
/// <param name="contents">The contents for this response.</param>
2522
public ImageGenerationResponse(IList<AIContent>? contents)
2623
{
27-
_contents = contents;
24+
Contents = contents;
2825
}
2926

3027
/// <summary>Gets or sets the raw representation of the image generation response from an underlying implementation.</summary>
@@ -46,8 +43,8 @@ public ImageGenerationResponse(IList<AIContent>? contents)
4643
[AllowNull]
4744
public IList<AIContent> Contents
4845
{
49-
get => _contents ??= [];
50-
set => _contents = value;
46+
get => field ??= [];
47+
set;
5148
}
5249

5350
/// <summary>Gets or sets usage details for the image generation response.</summary>

src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Azure/JsonSerialization/AzureStorageJsonUtilities.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ internal static partial class AzureStorageJsonUtilities
1313
{
1414
internal static class Default
1515
{
16-
private static JsonSerializerOptions? _options;
17-
internal static JsonSerializerOptions Options => _options ??= CreateJsonSerializerOptions(writeIndented: true);
16+
internal static JsonSerializerOptions Options => field ??= CreateJsonSerializerOptions(writeIndented: true);
1817
internal static JsonTypeInfo<CacheEntry> CacheEntryTypeInfo => Options.GetTypeInfo<CacheEntry>();
1918
internal static JsonTypeInfo<ScenarioRunResult> ScenarioRunResultTypeInfo => Options.GetTypeInfo<ScenarioRunResult>();
2019
}
2120

2221
internal static class Compact
2322
{
24-
private static JsonSerializerOptions? _options;
25-
internal static JsonSerializerOptions Options => _options ??= CreateJsonSerializerOptions(writeIndented: false);
23+
internal static JsonSerializerOptions Options => field ??= CreateJsonSerializerOptions(writeIndented: false);
2624
internal static JsonTypeInfo<CacheEntry> CacheEntryTypeInfo => Options.GetTypeInfo<CacheEntry>();
2725
internal static JsonTypeInfo<ScenarioRunResult> ScenarioRunResultTypeInfo => Options.GetTypeInfo<ScenarioRunResult>();
2826
}

0 commit comments

Comments
 (0)