Skip to content

Commit a4d52d0

Browse files
committed
Simplify logic
1 parent 181b4bc commit a4d52d0

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/NHibernate/Type/TypeFactory.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,16 @@ public static IType HeuristicType(string typeName)
535535
/// </remarks>
536536
public static IType HeuristicType(System.Type type)
537537
{
538-
return HeuristicType(type, parameters: null, length: null);
538+
// Use the basic name (such as String) to get the instance of the IType object.
539+
if (typeByTypeOfName.TryGetValue(type.AssemblyQualifiedName, out var returnType))
540+
{
541+
if (_obsoleteMessageByAlias.TryGetValue(type.AssemblyQualifiedName, out string obsoleteMessage))
542+
_log.Warn("{0} is obsolete. {1}", type.AssemblyQualifiedName, obsoleteMessage);
543+
544+
return returnType;
545+
}
546+
547+
return GetNHibernateTypeFromSystemType(type, null, null);
539548
}
540549

541550
/// <summary>
@@ -586,18 +595,12 @@ public static IType HeuristicType(string typeName, IDictionary<string, string> p
586595
{
587596
throw new MappingException("Could not find IType for given" + typeName + ": " + ex, ex);
588597
}
589-
return HeuristicType(typeClass, parameters, length, false);
598+
599+
return GetNHibernateTypeFromSystemType(typeClass, parameters, length);
590600
}
591601

592-
private static IType HeuristicType(System.Type typeClass, IDictionary<string, string> parameters, int? length, bool tryBasic = true)
602+
private static IType GetNHibernateTypeFromSystemType(System.Type typeClass, IDictionary<string, string> parameters, int? length)
593603
{
594-
if(tryBasic)
595-
{
596-
IType type = Basic(typeClass.AssemblyQualifiedName, parameters);
597-
598-
if (type != null)
599-
return type;
600-
}
601604
if (typeof(IType).IsAssignableFrom(typeClass))
602605
{
603606
try
@@ -610,6 +613,7 @@ private static IType HeuristicType(System.Type typeClass, IDictionary<string, st
610613
{
611614
_log.Warn("{0} is obsolete. {1}", typeClass.AssemblyQualifiedName, obsolete.Message);
612615
}
616+
613617
return type;
614618
}
615619
catch (HibernateException)
@@ -621,14 +625,17 @@ private static IType HeuristicType(System.Type typeClass, IDictionary<string, st
621625
throw new MappingException("Could not instantiate IType " + typeClass.Name + ": " + e, e);
622626
}
623627
}
628+
624629
if (typeof(ICompositeUserType).IsAssignableFrom(typeClass))
625630
{
626631
return new CompositeCustomType(typeClass, parameters);
627632
}
633+
628634
if (typeof(IUserType).IsAssignableFrom(typeClass))
629635
{
630636
return new CustomType(typeClass, parameters);
631637
}
638+
632639
if (typeof(ILifecycle).IsAssignableFrom(typeClass))
633640
{
634641
return NHibernateUtil.Entity(typeClass);

0 commit comments

Comments
 (0)