Skip to content

Commit b0f8cce

Browse files
committed
chore: upgrade src to c#12
This closes #659.
1 parent c67a9a8 commit b0f8cce

File tree

44 files changed

+174
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+174
-468
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ end_of_line = crlf
2323
insert_final_newline = true
2424

2525
#### Custom Analyzer Rules ####
26+
# Until https://github.com/SonarSource/sonar-dotnet/issues/7624 is shipped.
27+
dotnet_diagnostic.S3604.severity = none
2628

2729
dotnet_diagnostic.SA0001.severity = none
2830
dotnet_diagnostic.SA1600.severity = none

examples/Operator/Controller/V1TestEntityController.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,23 @@
1010
namespace Operator.Controller;
1111

1212
[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
13-
public class V1TestEntityController : IEntityController<V1TestEntity>
14-
{
15-
private readonly ILogger<V1TestEntityController> _logger;
16-
private readonly EntityRequeue<V1TestEntity> _requeue;
17-
private readonly EventPublisher _eventPublisher;
18-
19-
public V1TestEntityController(
20-
ILogger<V1TestEntityController> logger,
13+
public class V1TestEntityController(ILogger<V1TestEntityController> logger,
2114
EntityRequeue<V1TestEntity> requeue,
2215
EventPublisher eventPublisher)
23-
{
24-
_logger = logger;
25-
_requeue = requeue;
26-
_eventPublisher = eventPublisher;
27-
}
28-
16+
: IEntityController<V1TestEntity>
17+
{
2918
public async Task ReconcileAsync(V1TestEntity entity)
3019
{
31-
_logger.LogInformation("Reconciling entity {Entity}.", entity);
20+
logger.LogInformation("Reconciling entity {Entity}.", entity);
3221

33-
await _eventPublisher(entity, "RECONCILED", "Entity was reconciled.");
22+
await eventPublisher(entity, "RECONCILED", "Entity was reconciled.");
3423

35-
_requeue(entity, TimeSpan.FromSeconds(5));
24+
requeue(entity, TimeSpan.FromSeconds(5));
3625
}
3726

3827
public Task DeletedAsync(V1TestEntity entity)
3928
{
40-
_logger.LogInformation("Deleting entity {Entity}.", entity);
29+
logger.LogInformation("Deleting entity {Entity}.", entity);
4130
return Task.CompletedTask;
4231
}
4332
}

examples/WebhookOperator/Controller/V1TestEntityController.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,17 @@
66
namespace WebhookOperator.Controller;
77

88
[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
9-
public class V1TestEntityController : IEntityController<V1TestEntity>
9+
public class V1TestEntityController(ILogger<V1TestEntityController> logger) : IEntityController<V1TestEntity>
1010
{
11-
private readonly ILogger<V1TestEntityController> _logger;
12-
13-
public V1TestEntityController(
14-
ILogger<V1TestEntityController> logger)
15-
{
16-
_logger = logger;
17-
}
18-
1911
public Task ReconcileAsync(V1TestEntity entity)
2012
{
21-
_logger.LogInformation("Reconciling entity {Entity}.", entity);
13+
logger.LogInformation("Reconciling entity {Entity}.", entity);
2214
return Task.CompletedTask;
2315
}
2416

2517
public Task DeletedAsync(V1TestEntity entity)
2618
{
27-
_logger.LogInformation("Deleted entity {Entity}.", entity);
19+
logger.LogInformation("Deleted entity {Entity}.", entity);
2820
return Task.CompletedTask;
2921
}
3022
}

src/KubeOps.Abstractions/Entities/Attributes/AdditionalPrinterColumnAttribute.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
/// Defines a property as an additional printer column.
55
/// </summary>
66
[AttributeUsage(AttributeTargets.Property)]
7-
public class AdditionalPrinterColumnAttribute : Attribute
7+
public class AdditionalPrinterColumnAttribute(PrinterColumnPriority priority = default, string? name = null)
8+
: Attribute
89
{
9-
public AdditionalPrinterColumnAttribute(PrinterColumnPriority priority = default, string? name = null)
10-
{
11-
Name = name;
12-
Priority = priority;
13-
}
14-
1510
/// <summary>
1611
/// The name of the column. Defaults to the property-name.
1712
/// </summary>
18-
public string? Name { get; }
13+
public string? Name => name;
1914

2015
/// <summary>
2116
/// The priority of the additional printer column.
@@ -31,5 +26,5 @@ public AdditionalPrinterColumnAttribute(PrinterColumnPriority priority = default
3126
/// </item>
3227
/// </list>
3328
/// </summary>
34-
public PrinterColumnPriority Priority { get; }
29+
public PrinterColumnPriority Priority => priority;
3530
}

src/KubeOps.Abstractions/Entities/Attributes/DescriptionAttribute.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
/// XML documentation file.
66
/// </summary>
77
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
8-
public class DescriptionAttribute : Attribute
8+
public class DescriptionAttribute(string description) : Attribute
99
{
10-
public DescriptionAttribute(string description) => Description = description;
11-
1210
/// <summary>
1311
/// The given description for the property.
1412
/// </summary>
15-
public string Description { get; }
13+
public string Description => description;
1614
}

src/KubeOps.Abstractions/Entities/Attributes/EmbeddedResourceAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ namespace KubeOps.Abstractions.Entities.Attributes;
99
/// This implicitly sets the <see cref="PreserveUnknownFieldsAttribute"/>.
1010
/// </summary>
1111
[AttributeUsage(AttributeTargets.Property)]
12-
public class EmbeddedResourceAttribute : Attribute
13-
{
14-
}
12+
public class EmbeddedResourceAttribute : Attribute;
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
namespace KubeOps.Abstractions.Entities.Attributes;
22

33
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
4-
public class EntityScopeAttribute : Attribute
4+
public class EntityScopeAttribute(EntityScope scope = default) : Attribute
55
{
6-
public EntityScopeAttribute(EntityScope scope = default)
7-
{
8-
Scope = scope;
9-
}
10-
11-
public EntityScope Scope { get; }
6+
public EntityScope Scope => scope;
127
}

src/KubeOps.Abstractions/Entities/Attributes/ExternalDocsAttribute.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44
/// Defines that the property has an external documentation.
55
/// </summary>
66
[AttributeUsage(AttributeTargets.Property)]
7-
public class ExternalDocsAttribute : Attribute
7+
public class ExternalDocsAttribute(string url, string? description = null) : Attribute
88
{
9-
public ExternalDocsAttribute(string url, string? description = null)
10-
{
11-
Description = description;
12-
Url = url;
13-
}
14-
159
/// <summary>
1610
/// Additional description.
1711
/// </summary>
18-
public string? Description { get; }
12+
public string? Description => description;
1913

2014
/// <summary>
2115
/// Url where to find the documentation.
2216
/// </summary>
23-
public string Url { get; }
17+
public string Url => url;
2418
}

src/KubeOps.Abstractions/Entities/Attributes/IgnoreEntityAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
/// ignored during CRD generation.
66
/// </summary>
77
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
8-
public class IgnoreAttribute : Attribute
9-
{
10-
}
8+
public class IgnoreAttribute : Attribute;

src/KubeOps.Abstractions/Entities/Attributes/ItemsAttribute.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,23 @@
44
/// Define minimum and maximum items count for an array property.
55
/// </summary>
66
[AttributeUsage(AttributeTargets.Property)]
7-
public class ItemsAttribute : Attribute
7+
public class ItemsAttribute(long minItems = -1, long maxItems = -1) : Attribute
88
{
9-
public ItemsAttribute(long minItems = -1, long maxItems = -1)
10-
{
11-
MinItems = minItems switch
12-
{
13-
-1 => null,
14-
_ => minItems,
15-
};
16-
MaxItems = maxItems switch
17-
{
18-
-1 => null,
19-
_ => maxItems,
20-
};
21-
}
22-
239
/// <summary>
2410
/// Defines the minimal item count for the property.
2511
/// </summary>
26-
public long? MinItems { get; }
12+
public long? MinItems => minItems switch
13+
{
14+
-1 => null,
15+
_ => minItems,
16+
};
2717

2818
/// <summary>
2919
/// Defines the maximal item count for the property.
3020
/// </summary>
31-
public long? MaxItems { get; }
21+
public long? MaxItems => maxItems switch
22+
{
23+
-1 => null,
24+
_ => maxItems,
25+
};
3226
}

0 commit comments

Comments
 (0)