Skip to content

Commit a4542ab

Browse files
committed
Revert "Fixed R# warning: use extension blocks"
This reverts commit e8c2315.
1 parent e8c2315 commit a4542ab

File tree

39 files changed

+717
-903
lines changed

39 files changed

+717
-903
lines changed

src/Examples/DapperExample/Repositories/CommandDefinitionExtensions.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ internal static class CommandDefinitionExtensions
88
{
99
// SQL Server and MySQL require any active DbTransaction to be explicitly associated to the DbConnection.
1010

11-
extension(CommandDefinition command)
11+
public static CommandDefinition Associate(this CommandDefinition command, DbTransaction transaction)
1212
{
13-
public CommandDefinition Associate(DbTransaction transaction)
14-
{
15-
return new CommandDefinition(command.CommandText, command.Parameters, transaction, cancellationToken: command.CancellationToken);
16-
}
13+
return new CommandDefinition(command.CommandText, command.Parameters, transaction, cancellationToken: command.CancellationToken);
14+
}
1715

18-
public CommandDefinition Associate(AmbientTransaction? transaction)
19-
{
20-
return transaction != null
21-
? new CommandDefinition(command.CommandText, command.Parameters, transaction.Current, cancellationToken: command.CancellationToken)
22-
: command;
23-
}
16+
public static CommandDefinition Associate(this CommandDefinition command, AmbientTransaction? transaction)
17+
{
18+
return transaction != null
19+
? new CommandDefinition(command.CommandText, command.Parameters, transaction.Current, cancellationToken: command.CancellationToken)
20+
: command;
2421
}
2522
}

src/Examples/NoEntityFrameworkExample/Data/ResourceGraphExtensions.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ namespace NoEntityFrameworkExample.Data;
88

99
internal static class ResourceGraphExtensions
1010
{
11-
extension(IResourceGraph resourceGraph)
11+
public static IReadOnlyModel ToEntityModel(this IResourceGraph resourceGraph)
1212
{
13-
public IReadOnlyModel ToEntityModel()
14-
{
15-
var modelBuilder = new ModelBuilder();
16-
17-
foreach (ResourceType resourceType in resourceGraph.GetResourceTypes())
18-
{
19-
IncludeResourceType(resourceType, modelBuilder);
20-
}
13+
var modelBuilder = new ModelBuilder();
2114

22-
return modelBuilder.Model;
15+
foreach (ResourceType resourceType in resourceGraph.GetResourceTypes())
16+
{
17+
IncludeResourceType(resourceType, modelBuilder);
2318
}
19+
20+
return modelBuilder.Model;
2421
}
2522

2623
private static void IncludeResourceType(ResourceType resourceType, ModelBuilder builder)

src/JsonApiDotNetCore.Annotations/PolyfillCollectionExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ namespace JsonApiDotNetCore;
55
// These methods provide polyfills for lower .NET versions.
66
internal static class PolyfillCollectionExtensions
77
{
8-
extension<T>(HashSet<T> source)
8+
public static IReadOnlySet<T> AsReadOnly<T>(this HashSet<T> source)
99
{
10-
public IReadOnlySet<T> AsReadOnly()
11-
{
12-
return new ReadOnlySet<T>(source);
13-
}
10+
return new ReadOnlySet<T>(source);
1411
}
1512
}

src/JsonApiDotNetCore.Annotations/TypeExtensions.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,28 @@ namespace JsonApiDotNetCore;
22

33
internal static class TypeExtensions
44
{
5-
extension(Type? source)
5+
/// <summary>
6+
/// Whether the specified source type implements or equals the specified interface.
7+
/// </summary>
8+
public static bool IsOrImplementsInterface<TInterface>(this Type? source)
69
{
7-
/// <summary>
8-
/// Whether the specified source type implements or equals the specified interface.
9-
/// </summary>
10-
public bool IsOrImplementsInterface<TInterface>()
11-
{
12-
return IsOrImplementsInterface(source, typeof(TInterface));
13-
}
14-
15-
/// <summary>
16-
/// Whether the specified source type implements or equals the specified interface. This overload enables testing for an open generic interface.
17-
/// </summary>
18-
private bool IsOrImplementsInterface(Type interfaceType)
19-
{
20-
ArgumentNullException.ThrowIfNull(interfaceType);
10+
return IsOrImplementsInterface(source, typeof(TInterface));
11+
}
2112

22-
if (source == null)
23-
{
24-
return false;
25-
}
13+
/// <summary>
14+
/// Whether the specified source type implements or equals the specified interface. This overload enables testing for an open generic interface.
15+
/// </summary>
16+
private static bool IsOrImplementsInterface(this Type? source, Type interfaceType)
17+
{
18+
ArgumentNullException.ThrowIfNull(interfaceType);
2619

27-
return AreTypesEqual(interfaceType, source, interfaceType.IsGenericType) ||
28-
source.GetInterfaces().Any(type => AreTypesEqual(interfaceType, type, interfaceType.IsGenericType));
20+
if (source == null)
21+
{
22+
return false;
2923
}
24+
25+
return AreTypesEqual(interfaceType, source, interfaceType.IsGenericType) ||
26+
source.GetInterfaces().Any(type => AreTypesEqual(interfaceType, type, interfaceType.IsGenericType));
3027
}
3128

3229
private static bool AreTypesEqual(Type left, Type right, bool isLeftGeneric)

src/JsonApiDotNetCore.OpenApi.Swashbuckle/ActionDescriptorExtensions.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,33 @@ namespace JsonApiDotNetCore.OpenApi.Swashbuckle;
77

88
internal static class ActionDescriptorExtensions
99
{
10-
extension(ActionDescriptor descriptor)
10+
public static MethodInfo? TryGetActionMethod(this ActionDescriptor descriptor)
1111
{
12-
public MethodInfo? TryGetActionMethod()
13-
{
14-
ArgumentNullException.ThrowIfNull(descriptor);
15-
16-
if (descriptor is ControllerActionDescriptor controllerActionDescriptor)
17-
{
18-
return controllerActionDescriptor.MethodInfo;
19-
}
12+
ArgumentNullException.ThrowIfNull(descriptor);
2013

21-
return descriptor.EndpointMetadata.OfType<MethodInfo>().FirstOrDefault();
14+
if (descriptor is ControllerActionDescriptor controllerActionDescriptor)
15+
{
16+
return controllerActionDescriptor.MethodInfo;
2217
}
2318

24-
public ControllerParameterDescriptor? GetBodyParameterDescriptor()
25-
{
26-
ArgumentNullException.ThrowIfNull(descriptor);
19+
return descriptor.EndpointMetadata.OfType<MethodInfo>().FirstOrDefault();
20+
}
2721

28-
ParameterDescriptor? parameterDescriptor = descriptor.Parameters.FirstOrDefault(parameterDescriptor =>
29-
parameterDescriptor.BindingInfo?.BindingSource == BindingSource.Body);
22+
public static ControllerParameterDescriptor? GetBodyParameterDescriptor(this ActionDescriptor descriptor)
23+
{
24+
ArgumentNullException.ThrowIfNull(descriptor);
3025

31-
if (parameterDescriptor != null)
32-
{
33-
var controllerParameterDescriptor = parameterDescriptor as ControllerParameterDescriptor;
34-
ConsistencyGuard.ThrowIf(controllerParameterDescriptor == null);
26+
ParameterDescriptor? parameterDescriptor = descriptor.Parameters.FirstOrDefault(parameterDescriptor =>
27+
parameterDescriptor.BindingInfo?.BindingSource == BindingSource.Body);
3528

36-
return controllerParameterDescriptor;
37-
}
29+
if (parameterDescriptor != null)
30+
{
31+
var controllerParameterDescriptor = parameterDescriptor as ControllerParameterDescriptor;
32+
ConsistencyGuard.ThrowIf(controllerParameterDescriptor == null);
3833

39-
return null;
34+
return controllerParameterDescriptor;
4035
}
36+
37+
return null;
4138
}
4239
}

src/JsonApiDotNetCore.OpenApi.Swashbuckle/ObjectExtensions.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ internal static class ObjectExtensions
88
new(() => typeof(object).GetMethod(nameof(MemberwiseClone), BindingFlags.Instance | BindingFlags.NonPublic)!,
99
LazyThreadSafetyMode.ExecutionAndPublication);
1010

11-
extension<T>(T source)
11+
public static T MemberwiseClone<T>(this T source)
1212
where T : class
1313
{
14-
public T MemberwiseClone()
15-
{
16-
ArgumentNullException.ThrowIfNull(source);
14+
ArgumentNullException.ThrowIfNull(source);
1715

18-
return (T)MemberwiseCloneMethod.Value.Invoke(source, null)!;
19-
}
16+
return (T)MemberwiseCloneMethod.Value.Invoke(source, null)!;
2017
}
2118
}

src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiSchemaExtensions.cs

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,85 @@ namespace JsonApiDotNetCore.OpenApi.Swashbuckle;
44

55
internal static class OpenApiSchemaExtensions
66
{
7-
extension(IOpenApiSchema schema)
7+
public static OpenApiSchema AsInlineSchema(this IOpenApiSchema schema)
88
{
9-
public OpenApiSchema AsInlineSchema()
10-
{
11-
ConsistencyGuard.ThrowIf(schema is not OpenApiSchema);
12-
return (OpenApiSchema)schema;
13-
}
9+
ConsistencyGuard.ThrowIf(schema is not OpenApiSchema);
10+
return (OpenApiSchema)schema;
11+
}
1412

15-
public OpenApiSchemaReference AsReferenceSchema()
16-
{
17-
ConsistencyGuard.ThrowIf(schema is not OpenApiSchemaReference);
18-
return (OpenApiSchemaReference)schema;
19-
}
13+
public static OpenApiSchemaReference AsReferenceSchema(this IOpenApiSchema schema)
14+
{
15+
ConsistencyGuard.ThrowIf(schema is not OpenApiSchemaReference);
16+
return (OpenApiSchemaReference)schema;
2017
}
2118

22-
extension(OpenApiSchemaReference referenceSchema)
19+
public static string GetReferenceId(this OpenApiSchemaReference referenceSchema)
2320
{
24-
public string GetReferenceId()
25-
{
26-
string? schemaId = referenceSchema.Reference.Id;
27-
ConsistencyGuard.ThrowIf(schemaId is null);
28-
return schemaId;
29-
}
21+
string? schemaId = referenceSchema.Reference.Id;
22+
ConsistencyGuard.ThrowIf(schemaId is null);
23+
return schemaId;
3024
}
3125

32-
extension(OpenApiSchema inlineSchema)
26+
public static void SetNullable(this OpenApiSchema inlineSchema, bool nullable)
3327
{
34-
public void SetNullable(bool nullable)
35-
{
36-
ArgumentNullException.ThrowIfNull(inlineSchema);
28+
ArgumentNullException.ThrowIfNull(inlineSchema);
3729

38-
if (nullable)
39-
{
40-
inlineSchema.Type ??= JsonSchemaType.Null;
41-
inlineSchema.Type |= JsonSchemaType.Null;
42-
}
43-
else
30+
if (nullable)
31+
{
32+
inlineSchema.Type ??= JsonSchemaType.Null;
33+
inlineSchema.Type |= JsonSchemaType.Null;
34+
}
35+
else
36+
{
37+
if (inlineSchema.Type != null)
4438
{
45-
if (inlineSchema.Type != null)
46-
{
47-
inlineSchema.Type &= ~JsonSchemaType.Null;
48-
}
39+
inlineSchema.Type &= ~JsonSchemaType.Null;
4940
}
5041
}
42+
}
43+
44+
public static void ReorderProperties(this OpenApiSchema inlineSchema, IEnumerable<string> propertyNamesInOrder)
45+
{
46+
ArgumentNullException.ThrowIfNull(inlineSchema);
47+
ArgumentNullException.ThrowIfNull(propertyNamesInOrder);
5148

52-
public void ReorderProperties(IEnumerable<string> propertyNamesInOrder)
49+
if (inlineSchema.Properties is { Count: > 1 })
5350
{
54-
ArgumentNullException.ThrowIfNull(inlineSchema);
55-
ArgumentNullException.ThrowIfNull(propertyNamesInOrder);
51+
var propertiesInOrder = new Dictionary<string, IOpenApiSchema>();
5652

57-
if (inlineSchema.Properties is { Count: > 1 })
53+
foreach (string propertyName in propertyNamesInOrder)
5854
{
59-
var propertiesInOrder = new Dictionary<string, IOpenApiSchema>();
60-
61-
foreach (string propertyName in propertyNamesInOrder)
55+
if (inlineSchema.Properties.TryGetValue(propertyName, out IOpenApiSchema? schema))
6256
{
63-
if (inlineSchema.Properties.TryGetValue(propertyName, out IOpenApiSchema? schema))
64-
{
65-
propertiesInOrder.Add(propertyName, schema);
66-
}
57+
propertiesInOrder.Add(propertyName, schema);
6758
}
59+
}
6860

69-
ConsistencyGuard.ThrowIf(inlineSchema.Properties.Count != propertiesInOrder.Count);
61+
ConsistencyGuard.ThrowIf(inlineSchema.Properties.Count != propertiesInOrder.Count);
7062

71-
inlineSchema.Properties = propertiesInOrder;
72-
}
63+
inlineSchema.Properties = propertiesInOrder;
7364
}
7465
}
7566

76-
extension(IOpenApiSchema source)
67+
public static OpenApiSchema WrapInExtendedSchema(this IOpenApiSchema source)
7768
{
78-
public OpenApiSchema WrapInExtendedSchema()
79-
{
80-
ArgumentNullException.ThrowIfNull(source);
81-
82-
return new OpenApiSchema
83-
{
84-
AllOf = [source]
85-
};
86-
}
69+
ArgumentNullException.ThrowIfNull(source);
8770

88-
public IOpenApiSchema UnwrapLastExtendedSchema()
71+
return new OpenApiSchema
8972
{
90-
ArgumentNullException.ThrowIfNull(source);
73+
AllOf = [source]
74+
};
75+
}
9176

92-
if (source is OpenApiSchema && source.AllOf is { Count: > 0 })
93-
{
94-
return source.AllOf.Last();
95-
}
77+
public static IOpenApiSchema UnwrapLastExtendedSchema(this IOpenApiSchema source)
78+
{
79+
ArgumentNullException.ThrowIfNull(source);
9680

97-
return source;
81+
if (source is OpenApiSchema && source.AllOf is { Count: > 0 })
82+
{
83+
return source.AllOf.Last();
9884
}
85+
86+
return source;
9987
}
10088
}

src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaRepositoryExtensions.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@ namespace JsonApiDotNetCore.OpenApi.Swashbuckle;
66

77
internal static class SchemaRepositoryExtensions
88
{
9-
extension(SchemaRepository schemaRepository)
9+
public static OpenApiSchemaReference LookupByType(this SchemaRepository schemaRepository, Type schemaType)
1010
{
11-
public OpenApiSchemaReference LookupByType(Type schemaType)
12-
{
13-
ArgumentNullException.ThrowIfNull(schemaRepository);
14-
ArgumentNullException.ThrowIfNull(schemaType);
15-
16-
if (!schemaRepository.TryLookupByTypeSafe(schemaType, out OpenApiSchemaReference? referenceSchema))
17-
{
18-
throw new InvalidOperationException($"Reference schema for '{schemaType.Name}' does not exist.");
19-
}
20-
21-
return referenceSchema;
22-
}
11+
ArgumentNullException.ThrowIfNull(schemaRepository);
12+
ArgumentNullException.ThrowIfNull(schemaType);
2313

24-
public bool TryLookupByTypeSafe(Type type, [NotNullWhen(true)] out OpenApiSchemaReference? referenceSchema)
14+
if (!schemaRepository.TryLookupByTypeSafe(schemaType, out OpenApiSchemaReference? referenceSchema))
2515
{
26-
bool result = schemaRepository.TryLookupByType(type, out OpenApiSchemaReference? obliviousReferenceSchema);
27-
referenceSchema = result ? obliviousReferenceSchema : null;
28-
return result;
16+
throw new InvalidOperationException($"Reference schema for '{schemaType.Name}' does not exist.");
2917
}
18+
19+
return referenceSchema;
20+
}
21+
22+
public static bool TryLookupByTypeSafe(this SchemaRepository schemaRepository, Type type, [NotNullWhen(true)] out OpenApiSchemaReference? referenceSchema)
23+
{
24+
bool result = schemaRepository.TryLookupByType(type, out OpenApiSchemaReference? obliviousReferenceSchema);
25+
referenceSchema = result ? obliviousReferenceSchema : null;
26+
return result;
3027
}
3128
}

0 commit comments

Comments
 (0)