Skip to content

Commit 8b95e9b

Browse files
committed
remove unnecessary conditional compilation in EF Core
1 parent 6524e1b commit 8b95e9b

23 files changed

Lines changed: 14 additions & 133 deletions

File tree

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Sources/EntityFrameworkCore/Conventions/ThinktectureConventionSetPlugin.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ public ConventionSet ModifyConventions(ConventionSet conventionSet)
1717
{
1818
if (_settings?.IsEnabled == true)
1919
{
20-
var convention = new ThinktectureConventionsPlugin( _settings.UseConstructorForRead, _settings.ConfigureEnumsAndKeyedValueObjects);
20+
var convention = new ThinktectureConventionsPlugin(_settings.UseConstructorForRead, _settings.ConfigureEnumsAndKeyedValueObjects);
2121

2222
conventionSet.NavigationAddedConventions.Add(convention);
2323
conventionSet.PropertyAddedConventions.Add(convention);
2424
conventionSet.EntityTypeAddedConventions.Add(convention);
25-
26-
#if PRIMITIVE_COLLECTIONS
2725
conventionSet.PropertyElementTypeChangedConventions.Add(convention);
28-
#endif
2926
}
3027

3128
return conventionSet;

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Sources/EntityFrameworkCore/Conventions/ThinktectureConventionsPlugin.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ namespace Thinktecture.EntityFrameworkCore.Conventions;
1111
internal sealed class ThinktectureConventionsPlugin
1212
: INavigationAddedConvention,
1313
IPropertyAddedConvention,
14-
IEntityTypeAddedConvention
15-
#if PRIMITIVE_COLLECTIONS
16-
, IPropertyElementTypeChangedConvention
17-
#endif
14+
IEntityTypeAddedConvention,
15+
IPropertyElementTypeChangedConvention
1816
{
1917
private readonly bool _useConstructorForRead;
2018
private readonly Action<IConventionProperty> _configureEnumsAndKeyedValueObjects;
@@ -81,13 +79,11 @@ private static void AddNonKeyedValueObjectMembers(IConventionEntityTypeBuilder e
8179
if (entity.IsIgnored(member.Name))
8280
continue;
8381

84-
#if COMPLEX_TYPES
8582
var complexProperty = entity.FindComplexProperty(member);
8683

8784
// Ignore complex properties, even if it has an ObjectFactory
8885
if (complexProperty is not null)
8986
continue;
90-
#endif
9187

9288
var property = entity.FindProperty(member);
9389

@@ -106,7 +102,6 @@ public void ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, ICo
106102
ProcessProperty(propertyBuilder.Metadata);
107103
}
108104

109-
#if PRIMITIVE_COLLECTIONS
110105
public void ProcessPropertyElementTypeChanged(
111106
IConventionPropertyBuilder propertyBuilder,
112107
IElementType? newElementType,
@@ -129,7 +124,6 @@ public void ProcessPropertyElementTypeChanged(
129124
elementType.SetValueConverter(GetValueConverter(metadata));
130125
_configureEnumsAndKeyedValueObjects(propertyBuilder.Metadata);
131126
}
132-
#endif
133127

134128
private void ProcessNavigation(IConventionNavigation navigation)
135129
{

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Sources/Extensions/ComplexTypePropertyBuilderExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if COMPLEX_TYPES
2-
31
using Microsoft.EntityFrameworkCore.Metadata.Builders;
42
using Thinktecture.EntityFrameworkCore.Storage.ValueConversion;
53

@@ -42,4 +40,3 @@ public static ComplexTypePropertyBuilder<TProperty> HasThinktectureValueConverte
4240
return propertyBuilder;
4341
}
4442
}
45-
#endif

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Sources/Extensions/EntityTypeBuilderExtensions.cs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public static OwnedNavigationBuilder AddThinktectureValueConverters(
194194
return entityTypeBuilder;
195195
}
196196

197-
#if COMPLEX_TYPES
198197
/// <summary>
199198
/// Adds value converter to all properties that are Smart Enums or keyed Value Objects.
200199
/// Properties with a value provider are skipped.
@@ -273,7 +272,6 @@ public static ComplexPropertyBuilder AddThinktectureValueConverters(
273272

274273
return complexPropertyBuilder;
275274
}
276-
#endif
277275

278276
internal static void AddConvertersToEntity(
279277
this IMutableEntityType entity,
@@ -285,9 +283,7 @@ internal static void AddConvertersToEntity(
285283
AddNonKeyedValueObjectMembers(entity);
286284

287285
AddConverterForScalarProperties(entity, useConstructorForRead, configureEnumsAndKeyedValueObjects);
288-
#if COMPLEX_TYPES
289286
AddConverterForComplexProperties(entity, useConstructorForRead, configureEnumsAndKeyedValueObjects);
290-
#endif
291287
AddConvertersForNavigations(entity, useConstructorForRead, configureEnumsAndKeyedValueObjects);
292288

293289
if (addConvertersForOwnedTypes)
@@ -309,7 +305,6 @@ private static void AddSmartEnumAndKeyedValueObjects(
309305
}
310306
}
311307

312-
#if COMPLEX_TYPES
313308
private static void AddSmartEnumAndKeyedValueObjects(
314309
IMutableTypeBase entity,
315310
bool useConstructorForRead,
@@ -320,15 +315,9 @@ private static void AddSmartEnumAndKeyedValueObjects(
320315
AddConverterToNonNavigation(entity, propertyInfo, useConstructorForRead, configure);
321316
}
322317
}
323-
#endif
324318

325319
private static void AddConverterToNonNavigation(
326-
#if COMPLEX_TYPES
327-
IMutableTypeBase
328-
#else
329-
IMutableEntityType
330-
#endif
331-
entity,
320+
IMutableTypeBase entity,
332321
PropertyInfo propertyInfo,
333322
bool useConstructorForRead,
334323
Action<IMutableProperty> configure)
@@ -340,7 +329,6 @@ private static void AddConverterToNonNavigation(
340329
if (entity.FindProperty(propertyInfo) is not null)
341330
return;
342331

343-
#if COMPLEX_TYPES
344332
#if USE_FIND_COMPLEX_PROPERTY_FIX
345333
var complexProperty = entity.FindComplexPropertyFix(propertyInfo);
346334
#else
@@ -349,7 +337,6 @@ private static void AddConverterToNonNavigation(
349337
// will be handled by AddConverterForComplexProperties
350338
if (complexProperty is not null)
351339
return;
352-
#endif
353340

354341
if (!propertyInfo.IsCandidateProperty())
355342
return;
@@ -363,12 +350,7 @@ private static void AddConverterToNonNavigation(
363350
}
364351

365352
private static void AddNonKeyedValueObjectMembers(
366-
#if COMPLEX_TYPES
367-
IMutableTypeBase
368-
#else
369-
IMutableEntityType
370-
#endif
371-
entity)
353+
IMutableTypeBase entity)
372354
{
373355
if (!entity.ClrType.TryGetAssignableMembers(out var members))
374356
return;
@@ -378,16 +360,14 @@ private static void AddNonKeyedValueObjectMembers(
378360
if (entity.IsIgnored(member.Name))
379361
continue;
380362

381-
#if COMPLEX_TYPES
382363
#if USE_FIND_COMPLEX_PROPERTY_FIX
383364
var complexProperty = entity.FindComplexPropertyFix(member);
384365
#else
385-
var complexProperty = entity.FindComplexProperty(memberName);
366+
var complexProperty = entity.FindComplexProperty(member);
386367
#endif
387368
// will be handled by AddConverterForComplexProperties
388369
if (complexProperty is not null)
389370
continue;
390-
#endif
391371

392372
var property = entity.FindProperty(member);
393373

@@ -443,12 +423,7 @@ private static void AddConvertersForOwnedTypes(
443423
}
444424

445425
private static void AddConverterForScalarProperties(
446-
#if COMPLEX_TYPES
447-
IMutableTypeBase
448-
#else
449-
IMutableEntityType
450-
#endif
451-
entity,
426+
IMutableTypeBase entity,
452427
bool useConstructorForRead,
453428
Action<IMutableProperty> configure)
454429
{
@@ -459,13 +434,11 @@ private static void AddConverterForScalarProperties(
459434
if (valueConverter is not null)
460435
continue;
461436

462-
#if PRIMITIVE_COLLECTIONS
463437
if (property.IsPrimitiveCollection)
464438
{
465439
AddConverterForPrimitiveCollections(property, useConstructorForRead, configure);
466440
continue;
467441
}
468-
#endif
469442

470443
if (property.ClrType.FindMetadataForValueConverter() is not { } metadata)
471444
continue;
@@ -474,7 +447,6 @@ private static void AddConverterForScalarProperties(
474447
}
475448
}
476449

477-
#if PRIMITIVE_COLLECTIONS
478450
private static void AddConverterForPrimitiveCollections(
479451
IMutableProperty property,
480452
bool useConstructorForRead,
@@ -492,9 +464,7 @@ private static void AddConverterForPrimitiveCollections(
492464
elementType.SetValueConverter(valueConverter);
493465
configure(property);
494466
}
495-
#endif
496467

497-
#if COMPLEX_TYPES
498468
private static void AddConverterForComplexProperties(
499469
IMutableTypeBase entity,
500470
bool useConstructorForRead,
@@ -517,7 +487,6 @@ private static void AddConvertersForComplexProperty(
517487
AddConverterForScalarProperties(complexProperty.ComplexType, useConstructorForRead, configureEnumsAndKeyedValueObjects);
518488
AddConverterForComplexProperties(complexProperty.ComplexType, useConstructorForRead, configureEnumsAndKeyedValueObjects);
519489
}
520-
#endif
521490

522491
private static PropertyBuilder FindPropertyBuilder((EntityTypeBuilder?, OwnedNavigationBuilder?) builders, IMutableEntityType entityType, string propertyName)
523492
{

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Sources/Extensions/MutableTypeBaseExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if COMPLEX_TYPES
2-
31
using System.Reflection;
42
using Microsoft.EntityFrameworkCore.Metadata;
53

@@ -19,5 +17,3 @@ internal static class MutableTypeBaseExtensions
1917
};
2018
}
2119
}
22-
23-
#endif

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Sources/Extensions/PrimitiveCollectionBuilderExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if PRIMITIVE_COLLECTIONS
21
using Microsoft.EntityFrameworkCore.Metadata.Builders;
32
using Thinktecture.EntityFrameworkCore.Storage.ValueConversion;
43

@@ -27,4 +26,3 @@ public static PrimitiveCollectionBuilder<TProperty> HasThinktectureValueConverte
2726
return primitiveCollectionBuilder;
2827
}
2928
}
30-
#endif

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore10/Thinktecture.Runtime.Extensions.EntityFrameworkCore10.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions.</Description>
55
<PackageTags>smart-enum;value-object;discriminated-union;EntityFrameworkCore</PackageTags>
6-
<DefineConstants>$(DefineConstants);COMPLEX_TYPES;PRIMITIVE_COLLECTIONS;USE_FIND_COMPLEX_PROPERTY_FIX;</DefineConstants>
6+
<DefineConstants>$(DefineConstants);USE_FIND_COMPLEX_PROPERTY_FIX;</DefineConstants>
77
<TargetFramework>net10.0</TargetFramework>
88
</PropertyGroup>
99

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore8/Thinktecture.Runtime.Extensions.EntityFrameworkCore8.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions.</Description>
55
<PackageTags>smart-enum;value-object;discriminated-union;EntityFrameworkCore</PackageTags>
6-
<DefineConstants>$(DefineConstants);COMPLEX_TYPES;PRIMITIVE_COLLECTIONS;USE_FIND_COMPLEX_PROPERTY_FIX;</DefineConstants>
6+
<DefineConstants>$(DefineConstants);USE_FIND_COMPLEX_PROPERTY_FIX;</DefineConstants>
77
<TargetFramework>net8.0</TargetFramework>
88
</PropertyGroup>
99

src/Thinktecture.Runtime.Extensions.EntityFrameworkCore9/Thinktecture.Runtime.Extensions.EntityFrameworkCore9.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions.</Description>
55
<PackageTags>smart-enum;value-object;discriminated-union;EntityFrameworkCore</PackageTags>
6-
<DefineConstants>$(DefineConstants);COMPLEX_TYPES;PRIMITIVE_COLLECTIONS;USE_FIND_COMPLEX_PROPERTY_FIX;</DefineConstants>
6+
<DefineConstants>$(DefineConstants);USE_FIND_COMPLEX_PROPERTY_FIX;</DefineConstants>
77
<TargetFramework>net8.0</TargetFramework>
88
</PropertyGroup>
99

test/Thinktecture.Runtime.Extensions.EntityFrameworkCore.Tests.Sources/EntityFrameworkCore/ValueConversion/ValueObjectValueConverterFactoryTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ public async Task Should_write_and_read_enums_and_value_types()
4444
TestComplexValueObject_ObjectFactory_and_Constructor = TestComplexValueObject_ObjectFactory_and_Constructor.Create("value 6", "value 7"),
4545
CustomObject_ObjectFactory = new CustomObject_ObjectFactory("value 8", "value 9"),
4646
SmartEnum_IntBased = SmartEnum_IntBased.Item2,
47-
#if PRIMITIVE_COLLECTIONS
4847
CollectionOfIntBasedReferenceValueObject =
4948
[
5049
IntBasedReferenceValueObject.Create(1),
5150
IntBasedReferenceValueObject.Create(2)
5251
],
53-
#endif
5452
};
5553
_ctx.Add(entity);
5654
await _ctx.SaveChangesAsync();
@@ -122,7 +120,6 @@ await _ctx.TestEntities_with_Enum_and_ValueObjects
122120
.ToListAsync();
123121
}
124122

125-
#if COMPLEX_TYPES
126123
[Fact]
127124
public async Task Should_roundtrip_complex_value_object_with_complex_property()
128125
{
@@ -139,7 +136,6 @@ public async Task Should_roundtrip_complex_value_object_with_complex_property()
139136
loadedEntity.Id.Should().Be(entity.Id);
140137
loadedEntity.TestComplexType.Should().BeEquivalentTo(entity.TestComplexType);
141138
}
142-
#endif
143139

144140
public void Dispose()
145141
{

0 commit comments

Comments
 (0)