Skip to content

Commit 66bf311

Browse files
NH-3884 - Alternate implementation without a new method.
1 parent 5c5a64d commit 66bf311

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

src/NHibernate.Test/TypesTest/ChangeDefaultTypeFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ protected override void Configure(Configuration configuration)
2727
_testDefaultDateTimeType = NHibernateUtil.DateTime.Equals(_originalDefaultDateTimeType)
2828
? (IType) NHibernateUtil.Timestamp
2929
: NHibernateUtil.DateTime;
30-
TypeFactory.SetDefaultType<DateTime>(_testDefaultDateTimeType);
30+
TypeFactory.RegisterType(typeof(DateTime), _testDefaultDateTimeType, TypeFactory.EmptyAliases);
3131
base.Configure(configuration);
3232
}
3333

3434
protected override void DropSchema()
3535
{
3636
base.DropSchema();
3737
if (_originalDefaultDateTimeType != null)
38-
TypeFactory.SetDefaultType<DateTime>(_originalDefaultDateTimeType);
38+
TypeFactory.RegisterType(typeof(DateTime), _originalDefaultDateTimeType, TypeFactory.EmptyAliases);
3939
}
4040

4141
[Test]

src/NHibernate/Type/TypeFactory.cs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ private enum TypeClassification
3333
Length,
3434
PrecisionScale
3535
}
36-
37-
private static readonly string[] EmptyAliases= new string[0];
36+
37+
public static readonly string[] EmptyAliases = new string[0];
3838
private static readonly char[] PrecisionScaleSplit = { '(', ')', ',' };
3939
private static readonly char[] LengthSplit = { '(', ')' };
4040

@@ -92,7 +92,15 @@ private enum TypeClassification
9292

9393
private delegate NullableType NullableTypeCreatorDelegate(SqlType sqlType);
9494

95-
private static void RegisterType(System.Type systemType, IType nhibernateType, IEnumerable<string> aliases)
95+
/// <summary>
96+
/// <para>Defines which NHibernate type should be chosen by default for handling a given .Net type.</para>
97+
/// <para>This must be done before any operation on NHibernate, including building its
98+
/// <see cref="Configuration" /> and building session factory. Otherwise the behavior will be undefined.</para>
99+
/// </summary>
100+
/// <param name="systemType">The .Net type.</param>
101+
/// <param name="nhibernateType">The NHibernate type.</param>
102+
/// <param name="aliases">The additional aliases to map to the type. Use <see cref="EmptyAliases"/> if none.</param>
103+
public static void RegisterType(System.Type systemType, IType nhibernateType, IEnumerable<string> aliases)
96104
{
97105
var typeAliases = new List<string>(aliases);
98106
typeAliases.AddRange(GetClrTypeAliases(systemType));
@@ -280,25 +288,6 @@ private static void RegisterBuiltInTypes()
280288
len => new SerializableType(typeof (object), SqlTypeFactory.GetBinary(len))));
281289
}
282290

283-
/// <summary>
284-
/// <para>Defines which NHibernate type should be chosen by default for handling a given .Net type.</para>
285-
/// <para>This must be done before any operation on NHibernate, including building its
286-
/// <see cref="Configuration" /> and building session factory. Otherwise the behavior will be undefined.</para>
287-
/// </summary>
288-
/// <param name="targetType">The NHibernate type.</param>
289-
/// <typeparam name="T">The .Net type.</typeparam>
290-
public static void SetDefaultType<T>(IType targetType)
291-
{
292-
if (targetType == null)
293-
throw new ArgumentNullException(nameof(targetType));
294-
295-
var type = typeof(T);
296-
foreach (var alias in GetClrTypeAliases(type))
297-
{
298-
typeByTypeOfName[alias] = targetType;
299-
}
300-
}
301-
302291
private static ICollectionTypeFactory CollectionTypeFactory =>
303292
Environment.BytecodeProvider.CollectionTypeFactory;
304293

0 commit comments

Comments
 (0)