Skip to content

Commit 23fe01d

Browse files
authored
Replace usage of GenericEnumMapper with native EnumStringType<> (#562)
+semver:feature
1 parent d86c035 commit 23fe01d

File tree

11 files changed

+51
-31
lines changed

11 files changed

+51
-31
lines changed

src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System.Linq;
22
using FluentNHibernate.Automapping;
3-
using FluentNHibernate.Mapping;
43
using FluentNHibernate.MappingModel.ClassBased;
54
using FluentNHibernate.Specs.Automapping.Fixtures;
65
using Machine.Specifications;
76
using FluentAssertions;
7+
using NHibernate.Type;
88

99
namespace FluentNHibernate.Specs.Automapping
1010
{
@@ -34,8 +34,8 @@ public class when_the_automapper_is_told_to_map_an_entity_with_a_enum_property :
3434
It should_create_a_property_mapping_for_the_property = () =>
3535
mapping.Properties.ShouldContain(x => x.Name == "EnumProperty");
3636

37-
It should_use_the_generic_enum_mapper_for_the_property = () =>
38-
mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(GenericEnumMapper<Enum>));
37+
It should_use_the_enum_string_type_for_the_property = () =>
38+
mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType<Enum>));
3939

4040
It should_create_a_column_for_the_property_mapping_with_the_property_name = () =>
4141
mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty");
@@ -52,8 +52,8 @@ public class when_the_automapper_is_told_to_map_an_entity_with_a_nullable_enum_p
5252
It should_create_a_property_mapping_for_the_property = () =>
5353
mapping.Properties.ShouldContain(x => x.Name == "EnumProperty");
5454

55-
It should_use_the_generic_enum_mapper_for_the_property = () =>
56-
mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(GenericEnumMapper<Enum>));
55+
It should_use_the_enum_string_mapper_for_the_property = () =>
56+
mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType<Enum>));
5757

5858
It should_create_a_column_for_the_property_mapping_with_the_property_name = () =>
5959
mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty");

src/FluentNHibernate.Testing/AutoMapping/Overrides/CompositeIdOverrides.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Linq;
33
using FluentNHibernate.Automapping;
4-
using FluentNHibernate.Mapping;
54
using FluentNHibernate.MappingModel.Identity;
5+
using NHibernate.Type;
66
using NUnit.Framework;
77

88
namespace FluentNHibernate.Testing.AutoMapping.Overrides
@@ -60,7 +60,7 @@ public void ShouldMapEnumIdAsAString()
6060
//of getting to the key type though
6161
firstKey.ShouldBeOfType(typeof(KeyPropertyMapping));
6262
var keyProp = (KeyPropertyMapping)firstKey;
63-
keyProp.Type.GetUnderlyingSystemType().ShouldEqual(typeof(GenericEnumMapper<>).MakeGenericType(typeof(SomeEnum)));
63+
keyProp.Type.GetUnderlyingSystemType().ShouldEqual(typeof(EnumStringType<>).MakeGenericType(typeof(SomeEnum)));
6464
});
6565
}
6666

src/FluentNHibernate.Testing/DomainModel/Mapping/ClassMapXmlCreationTester.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using FluentNHibernate.MappingModel;
55
using NUnit.Framework;
66
using FluentNHibernate.Mapping;
7+
using NHibernate.Type;
78

89
namespace FluentNHibernate.Testing.DomainModel.Mapping
910
{
@@ -218,13 +219,13 @@ public void DoubleNotWorksCorrectly()
218219
}
219220

220221
[Test]
221-
public void Map_an_enumeration()
222+
public void MapAnEnumeration()
222223
{
223224
new MappingTester<MappedObject>()
224225
.ForMapping(m => m.Map(x => x.Color))
225226
.Element("class/property[@name='Color']")
226227
.Exists()
227-
.HasAttribute("type", typeof(GenericEnumMapper<ColorEnum>).AssemblyQualifiedName)
228+
.HasAttribute("type", typeof(EnumStringType<ColorEnum>).AssemblyQualifiedName)
228229
.Element("class/property[@name='Color']/column")
229230
.Exists();
230231
}
@@ -236,7 +237,7 @@ public void MapANullableEnumeration()
236237
.ForMapping(m => m.Map(x => x.NullableColor))
237238
.Element("class/property[@name='NullableColor']")
238239
.Exists()
239-
.HasAttribute("type", typeof(GenericEnumMapper<ColorEnum>).AssemblyQualifiedName)
240+
.HasAttribute("type", typeof(EnumStringType<ColorEnum>).AssemblyQualifiedName)
240241
.Element("class/property[@name='NullableColor']/column")
241242
.Exists()
242243
.HasAttribute("not-null", "false");

src/FluentNHibernate.Testing/DomainModel/Mapping/CompositeIdentityPartTester.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System;
21
using System.Linq;
3-
using FluentNHibernate.Mapping;
42
using FluentNHibernate.Mapping.Providers;
53
using FluentNHibernate.MappingModel.ClassBased;
4+
using NHibernate.Type;
65
using NUnit.Framework;
76

87
namespace FluentNHibernate.Testing.DomainModel.Mapping
@@ -89,7 +88,7 @@ public void KeyPropertyEnumShouldBeStringByDefault()
8988
c.CompositeId()
9089
.KeyProperty(x => x.EnumProperty))
9190
.Element("class/composite-id/key-property")
92-
.HasAttribute("type", typeof(GenericEnumMapper<SomeEnum>).AssemblyQualifiedName);
91+
.HasAttribute("type", typeof(EnumStringType<SomeEnum>).AssemblyQualifiedName);
9392
}
9493

9594
[Test]

src/FluentNHibernate.Testing/FluentInterfaceTests/PropertyEnumerablesTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Linq;
2-
using FluentNHibernate.Mapping;
2+
using NHibernate.Type;
33
using NUnit.Framework;
44

55
namespace FluentNHibernate.Testing.FluentInterfaceTests
@@ -19,19 +19,19 @@ public void ShouldSetNullableEnumsToNullable()
1919
}
2020

2121
[Test]
22-
public void ShouldSetNullableEnumsToUseGenericEnumMapper()
22+
public void ShouldSetNullableEnumsToUseEnumStringType()
2323
{
2424
Property<Target>(x => x.NullableEnum)
2525
.Mapping(m => {})
26-
.ModelShouldMatch(x => x.Type.GetUnderlyingSystemType().ShouldEqual(typeof(GenericEnumMapper<Enum>)));
26+
.ModelShouldMatch(x => x.Type.GetUnderlyingSystemType().ShouldEqual(typeof(EnumStringType<Enum>)));
2727
}
2828

2929
[Test]
30-
public void ShouldSetEnumsToUseGenericEnumMapper()
30+
public void ShouldSetEnumsToUseEnumStringType()
3131
{
3232
Property<Target>(x => x.Enum)
3333
.Mapping(m => { })
34-
.ModelShouldMatch(x => x.Type.GetUnderlyingSystemType().ShouldEqual(typeof(GenericEnumMapper<Enum>)));
34+
.ModelShouldMatch(x => x.Type.GetUnderlyingSystemType().ShouldEqual(typeof(EnumStringType<Enum>)));
3535
}
3636

3737
private class Target
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
using FluentNHibernate.MappingModel;
1+
using System;
2+
using FluentNHibernate.MappingModel;
23
using NUnit.Framework;
34
using FluentNHibernate.Mapping;
5+
using NHibernate.Type;
46

57
namespace FluentNHibernate.Testing.Utils
68
{
79
[TestFixture]
810
public class TypeReferenceEnumTests
911
{
1012
[Test]
13+
public void IsEnumOnTypeReferenceToEnumStringTypeShouldBeTrue()
14+
{
15+
var enumTypeReference = new TypeReference(typeof(EnumStringType<TestEnum>));
16+
enumTypeReference.IsEnum.ShouldBeTrue();
17+
}
18+
19+
[Test, Obsolete]
1120
public void IsEnumOnTypeReferenceToGenericEnumMapperShouldBeTrue()
1221
{
1322
var enumTypeReference = new TypeReference(typeof(GenericEnumMapper<TestEnum>));
@@ -18,7 +27,5 @@ private enum TestEnum
1827
{
1928
Value1
2029
}
21-
22-
2330
}
2431
}

src/FluentNHibernate/Automapping/Steps/PropertyStep.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using FluentNHibernate.Mapping;
77
using FluentNHibernate.MappingModel;
88
using FluentNHibernate.MappingModel.ClassBased;
9-
using FluentNHibernate.MappingModel.Collections;
109
using FluentNHibernate.Utils;
10+
using NHibernate.Type;
1111

1212
namespace FluentNHibernate.Automapping.Steps
1313
{
@@ -116,10 +116,10 @@ static TypeReference GetDefaultType(Member property)
116116
var type = new TypeReference(property.PropertyType);
117117

118118
if (property.PropertyType.IsEnum())
119-
type = new TypeReference(typeof(GenericEnumMapper<>).MakeGenericType(property.PropertyType));
119+
type = new TypeReference(typeof(EnumStringType<>).MakeGenericType(property.PropertyType));
120120

121121
if (property.PropertyType.IsNullable() && property.PropertyType.IsEnum())
122-
type = new TypeReference(typeof(GenericEnumMapper<>).MakeGenericType(property.PropertyType.GetGenericArguments()[0]));
122+
type = new TypeReference(typeof(EnumStringType<>).MakeGenericType(property.PropertyType.GetGenericArguments()[0]));
123123

124124
return type;
125125
}

src/FluentNHibernate/Mapping/CompositeIdentityPart.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using FluentNHibernate.MappingModel;
88
using FluentNHibernate.MappingModel.Identity;
99
using FluentNHibernate.Utils;
10+
using NHibernate.Type;
1011

1112
namespace FluentNHibernate.Mapping
1213
{
@@ -74,7 +75,7 @@ protected virtual CompositeIdentityPart<T> KeyProperty(Member member, string col
7475
var type = member.PropertyType;
7576

7677
if (type.IsEnum)
77-
type = typeof(GenericEnumMapper<>).MakeGenericType(type);
78+
type = typeof(EnumStringType<>).MakeGenericType(type);
7879

7980
var key = new KeyPropertyMapping
8081
{

src/FluentNHibernate/Mapping/GenericEnumMapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace FluentNHibernate.Mapping
55
{
6+
[Obsolete("Please use EnumStringType<T> instead")]
67
[Serializable]
78
public class GenericEnumMapper<TEnum> : EnumStringType
89
{

src/FluentNHibernate/Mapping/PropertyPart.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using FluentNHibernate.Mapping.Providers;
55
using FluentNHibernate.MappingModel;
66
using FluentNHibernate.Utils;
7+
using NHibernate.Type;
78
using NHibernate.UserTypes;
89

910
namespace FluentNHibernate.Mapping
@@ -353,10 +354,10 @@ TypeReference GetDefaultType()
353354
var type = new TypeReference(member.PropertyType);
354355

355356
if (member.PropertyType.IsEnum())
356-
type = new TypeReference(typeof(GenericEnumMapper<>).MakeGenericType(member.PropertyType));
357+
type = new TypeReference(typeof(EnumStringType<>).MakeGenericType(member.PropertyType));
357358

358359
if (member.PropertyType.IsNullable() && member.PropertyType.IsEnum())
359-
type = new TypeReference(typeof(GenericEnumMapper<>).MakeGenericType(member.PropertyType.GetGenericArguments()[0]));
360+
type = new TypeReference(typeof(EnumStringType<>).MakeGenericType(member.PropertyType.GetGenericArguments()[0]));
360361

361362
return type;
362363
}

0 commit comments

Comments
 (0)