Skip to content

Commit 23e5ba4

Browse files
author
Bart Koelman
committed
Fixed cibuild
1 parent e644a0f commit 23e5ba4

File tree

8 files changed

+25
-42
lines changed

8 files changed

+25
-42
lines changed

src/JsonApiDotNetCore/Hooks/Internal/HooksNavigationParser.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
using System.Linq.Expressions;
33
using System.Reflection;
44

5+
#pragma warning disable AV1008 // Class should not be static
6+
57
namespace JsonApiDotNetCore.Hooks.Internal
68
{
7-
internal sealed class HooksNavigationParser
9+
internal static class HooksNavigationParser
810
{
911
/// <summary>
1012
/// Gets the property info that is referenced in the NavigationAction expression. Credits: https://stackoverflow.com/a/17116267/4441216

src/JsonApiDotNetCore/Queries/Internal/QueryableBuilding/WhereClauseBuilder.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace JsonApiDotNetCore.Queries.Internal.QueryableBuilding
1717
[PublicAPI]
1818
public class WhereClauseBuilder : QueryClauseBuilder<Type>
1919
{
20-
private static readonly RuntimeTypeConverter TypeConverter = new RuntimeTypeConverter();
2120
private static readonly CollectionConverter CollectionConverter = new CollectionConverter();
2221
private static readonly ConstantExpression NullConstant = Expression.Constant(null);
2322

@@ -190,7 +189,7 @@ private Type TryResolveCommonType(QueryExpression left, QueryExpression right)
190189
{
191190
Type leftType = ResolveFixedType(left);
192191

193-
if (TypeConverter.CanContainNull(leftType))
192+
if (RuntimeTypeConverter.CanContainNull(leftType))
194193
{
195194
return leftType;
196195
}
@@ -202,7 +201,7 @@ private Type TryResolveCommonType(QueryExpression left, QueryExpression right)
202201

203202
Type rightType = TryResolveFixedType(right);
204203

205-
if (rightType != null && TypeConverter.CanContainNull(rightType))
204+
if (rightType != null && RuntimeTypeConverter.CanContainNull(rightType))
206205
{
207206
return rightType;
208207
}
@@ -260,7 +259,7 @@ private static object ConvertTextToTargetType(string text, Type targetType)
260259
{
261260
try
262261
{
263-
return TypeConverter.ConvertType(text, targetType);
262+
return RuntimeTypeConverter.ConvertType(text, targetType);
264263
}
265264
catch (FormatException exception)
266265
{

src/JsonApiDotNetCore/Resources/Identifiable.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public abstract class Identifiable : Identifiable<int>
1616
/// </typeparam>
1717
public abstract class Identifiable<TId> : IIdentifiable<TId>
1818
{
19-
private static readonly RuntimeTypeConverter TypeConverter = new RuntimeTypeConverter();
20-
2119
/// <inheritdoc />
2220
public virtual TId Id { get; set; }
2321

@@ -46,7 +44,7 @@ protected virtual string GetStringId(TId value)
4644
/// </summary>
4745
protected virtual TId GetTypedId(string value)
4846
{
49-
return value == null ? default : (TId)TypeConverter.ConvertType(value, typeof(TId));
47+
return value == null ? default : (TId)RuntimeTypeConverter.ConvertType(value, typeof(TId));
5048
}
5149
}
5250
}

src/JsonApiDotNetCore/RuntimeTypeConverter.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22

3+
#pragma warning disable AV1008 // Class should not be static
4+
35
namespace JsonApiDotNetCore
46
{
5-
internal sealed class RuntimeTypeConverter
7+
internal static class RuntimeTypeConverter
68
{
7-
public object ConvertType(object value, Type type)
9+
public static object ConvertType(object value, Type type)
810
{
911
ArgumentGuard.NotNull(type, nameof(type));
1012

@@ -73,12 +75,12 @@ public object ConvertType(object value, Type type)
7375
}
7476
}
7577

76-
public bool CanContainNull(Type type)
78+
public static bool CanContainNull(Type type)
7779
{
7880
return !type.IsValueType || Nullable.GetUnderlyingType(type) != null;
7981
}
8082

81-
public object GetDefaultValue(Type type)
83+
public static object GetDefaultValue(Type type)
8284
{
8385
return type.IsValueType ? Activator.CreateInstance(type) : null;
8486
}

src/JsonApiDotNetCore/Serialization/BaseDeserializer.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace JsonApiDotNetCore.Serialization
2121
[PublicAPI]
2222
public abstract class BaseDeserializer
2323
{
24-
private protected static readonly RuntimeTypeConverter TypeConverter = new RuntimeTypeConverter();
2524
private protected static readonly CollectionConverter CollectionConverter = new CollectionConverter();
2625

2726
protected IResourceContextProvider ResourceContextProvider { get; }
@@ -349,7 +348,7 @@ private object ConvertAttrValue(object newValue, Type targetType)
349348
}
350349

351350
// the attribute value is a native C# type.
352-
object convertedValue = TypeConverter.ConvertType(newValue, targetType);
351+
object convertedValue = RuntimeTypeConverter.ConvertType(newValue, targetType);
353352
return convertedValue;
354353
}
355354

src/JsonApiDotNetCore/Serialization/Building/ResourceObjectBuilder.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace JsonApiDotNetCore.Serialization.Building
1313
[PublicAPI]
1414
public class ResourceObjectBuilder : IResourceObjectBuilder
1515
{
16-
private static readonly RuntimeTypeConverter TypeConverter = new RuntimeTypeConverter();
1716
private static readonly CollectionConverter CollectionConverter = new CollectionConverter();
1817

1918
private readonly ResourceObjectBuilderSettings _settings;
@@ -175,7 +174,7 @@ private void ProcessAttributes(IIdentifiable resource, IEnumerable<AttrAttribute
175174
}
176175

177176
if (_settings.SerializerDefaultValueHandling == DefaultValueHandling.Ignore &&
178-
Equals(value, TypeConverter.GetDefaultValue(attr.Property.PropertyType)))
177+
Equals(value, RuntimeTypeConverter.GetDefaultValue(attr.Property.PropertyType)))
179178
{
180179
return;
181180
}

src/JsonApiDotNetCore/Serialization/RequestDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private void AssertCompatibleId(ResourceIdentifierObject resourceIdentifierObjec
260260
{
261261
try
262262
{
263-
TypeConverter.ConvertType(resourceIdentifierObject.Id, idType);
263+
RuntimeTypeConverter.ConvertType(resourceIdentifierObject.Id, idType);
264264
}
265265
catch (FormatException exception)
266266
{

test/UnitTests/Internal/RuntimeTypeConverterTests.cs

+9-25
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ public void Can_Convert_DateTimeOffsets()
1414
var dto = new DateTimeOffset(new DateTime(2002, 2, 2), TimeSpan.FromHours(4));
1515
string formattedString = dto.ToString("O");
1616

17-
var typeConverter = new RuntimeTypeConverter();
18-
1917
// Act
20-
object result = typeConverter.ConvertType(formattedString, typeof(DateTimeOffset));
18+
object result = RuntimeTypeConverter.ConvertType(formattedString, typeof(DateTimeOffset));
2119

2220
// Assert
2321
Assert.Equal(dto, result);
@@ -29,10 +27,8 @@ public void Bad_DateTimeOffset_String_Throws()
2927
// Arrange
3028
const string formattedString = "this_is_not_a_valid_dto";
3129

32-
var typeConverter = new RuntimeTypeConverter();
33-
3430
// Act
35-
Action action = () => typeConverter.ConvertType(formattedString, typeof(DateTimeOffset));
31+
Action action = () => RuntimeTypeConverter.ConvertType(formattedString, typeof(DateTimeOffset));
3632

3733
// Assert
3834
Assert.Throws<FormatException>(action);
@@ -44,10 +40,8 @@ public void Can_Convert_Enums()
4440
// Arrange
4541
const string formattedString = "1";
4642

47-
var typeConverter = new RuntimeTypeConverter();
48-
4943
// Act
50-
object result = typeConverter.ConvertType(formattedString, typeof(TestEnum));
44+
object result = RuntimeTypeConverter.ConvertType(formattedString, typeof(TestEnum));
5145

5246
// Assert
5347
Assert.Equal(TestEnum.Test, result);
@@ -60,10 +54,8 @@ public void ConvertType_Returns_Value_If_Type_Is_Same()
6054
var val = new ComplexType();
6155
Type type = val.GetType();
6256

63-
var typeConverter = new RuntimeTypeConverter();
64-
6557
// Act
66-
object result = typeConverter.ConvertType(val, type);
58+
object result = RuntimeTypeConverter.ConvertType(val, type);
6759

6860
// Assert
6961
Assert.Equal(val, result);
@@ -78,11 +70,9 @@ public void ConvertType_Returns_Value_If_Type_Is_Assignable()
7870
Type baseType = typeof(BaseType);
7971
Type iType = typeof(IType);
8072

81-
var typeConverter = new RuntimeTypeConverter();
82-
8373
// Act
84-
object baseResult = typeConverter.ConvertType(val, baseType);
85-
object iResult = typeConverter.ConvertType(val, iType);
74+
object baseResult = RuntimeTypeConverter.ConvertType(val, baseType);
75+
object iResult = RuntimeTypeConverter.ConvertType(val, iType);
8676

8777
// Assert
8878
Assert.Equal(val, baseResult);
@@ -102,12 +92,10 @@ public void ConvertType_Returns_Default_Value_For_Empty_Strings()
10292
{ typeof(Guid), Guid.Empty }
10393
};
10494

105-
var typeConverter = new RuntimeTypeConverter();
106-
10795
foreach (KeyValuePair<Type, object> pair in data)
10896
{
10997
// Act
110-
object result = typeConverter.ConvertType(string.Empty, pair.Key);
98+
object result = RuntimeTypeConverter.ConvertType(string.Empty, pair.Key);
11199

112100
// Assert
113101
Assert.Equal(pair.Value, result);
@@ -121,10 +109,8 @@ public void Can_Convert_TimeSpans()
121109
TimeSpan timeSpan = TimeSpan.FromMinutes(45);
122110
string stringSpan = timeSpan.ToString();
123111

124-
var typeConverter = new RuntimeTypeConverter();
125-
126112
// Act
127-
object result = typeConverter.ConvertType(stringSpan, typeof(TimeSpan));
113+
object result = RuntimeTypeConverter.ConvertType(stringSpan, typeof(TimeSpan));
128114

129115
// Assert
130116
Assert.Equal(timeSpan, result);
@@ -136,10 +122,8 @@ public void Bad_TimeSpanString_Throws()
136122
// Arrange
137123
const string formattedString = "this_is_not_a_valid_timespan";
138124

139-
var typeConverter = new RuntimeTypeConverter();
140-
141125
// Act
142-
Action action = () => typeConverter.ConvertType(formattedString, typeof(TimeSpan));
126+
Action action = () => RuntimeTypeConverter.ConvertType(formattedString, typeof(TimeSpan));
143127

144128
// Assert
145129
Assert.Throws<FormatException>(action);

0 commit comments

Comments
 (0)