@@ -535,7 +535,7 @@ public static IType HeuristicType(string typeName)
535
535
/// </remarks>
536
536
public static IType HeuristicType ( System . Type type )
537
537
{
538
- return HeuristicType ( type , typeName : null , parameters : null , length : null ) ;
538
+ return HeuristicType ( type , parameters : null , length : null ) ;
539
539
}
540
540
541
541
/// <summary>
@@ -558,56 +558,50 @@ public static IType HeuristicType(string typeName, IDictionary<string, string> p
558
558
/// <returns></returns>
559
559
public static IType HeuristicType ( string typeName , IDictionary < string , string > parameters , int ? length )
560
560
{
561
- return HeuristicType ( /*resolvedType:*/ null , typeName , parameters , length ) ;
562
- }
563
-
564
- /// <summary>
565
- /// Provide either resolvedType or typeName. resolvedType takes precedence.
566
- /// </summary>
567
- private static IType HeuristicType ( System . Type resolvedType , string typeName , IDictionary < string , string > parameters , int ? length )
568
- {
569
- IType type = Basic ( resolvedType ? . AssemblyQualifiedName ?? typeName , parameters ) ;
561
+ IType type = Basic ( typeName , parameters ) ;
570
562
571
563
if ( type != null )
572
564
return type ;
573
565
574
- if ( resolvedType == null )
566
+ string [ ] parsedTypeName ;
567
+ var typeClassification = GetTypeClassification ( typeName ) ;
568
+ if ( typeClassification == TypeClassification . LengthOrScale )
575
569
{
576
- string [ ] parsedTypeName ;
577
- var typeClassification = GetTypeClassification ( typeName ) ;
578
- if ( typeClassification == TypeClassification . LengthOrScale )
570
+ parsedTypeName = typeName . Split ( LengthSplit ) ;
571
+ if ( ! int . TryParse ( parsedTypeName [ 1 ] , out int parsedLength ) )
579
572
{
580
- parsedTypeName = typeName . Split ( LengthSplit ) ;
581
- if ( ! int . TryParse ( parsedTypeName [ 1 ] , out int parsedLength ) )
582
- {
583
- throw new MappingException ( $ "Could not parse length value '{ parsedTypeName [ 1 ] } ' as int for type '{ typeName } '") ;
584
- }
585
- length = parsedLength ;
573
+ throw new MappingException ( $ "Could not parse length value '{ parsedTypeName [ 1 ] } ' as int for type '{ typeName } '") ;
586
574
}
587
- else
588
- parsedTypeName = typeClassification == TypeClassification . PrecisionScale ? typeName . Split ( PrecisionScaleSplit ) : new [ ] { typeName } ;
575
+ length = parsedLength ;
576
+ }
577
+ else
578
+ parsedTypeName = typeClassification == TypeClassification . PrecisionScale ? typeName . Split ( PrecisionScaleSplit ) : new [ ] { typeName } ;
589
579
590
- try
591
- {
592
- resolvedType = ReflectHelper . ClassForName ( parsedTypeName [ 0 ] ) ; //typeName);
593
- }
594
- catch ( Exception )
595
- {
596
- return null ;
597
- }
580
+ System . Type typeClass ;
581
+ try
582
+ {
583
+ typeClass = ReflectHelper . ClassForName ( parsedTypeName [ 0 ] ) ; //typeName);
584
+ }
585
+ catch ( Exception )
586
+ {
587
+ return null ;
598
588
}
599
- var typeClass = resolvedType ;
589
+ return HeuristicType ( typeClass , parameters , length ) ;
590
+ }
591
+
592
+ private static IType HeuristicType ( System . Type typeClass , IDictionary < string , string > parameters , int ? length )
593
+ {
600
594
if ( typeof ( IType ) . IsAssignableFrom ( typeClass ) )
601
595
{
602
596
try
603
597
{
604
- type = ( IType ) Environment . ObjectsFactory . CreateInstance ( typeClass ) ;
598
+ var type = ( IType ) Environment . ObjectsFactory . CreateInstance ( typeClass ) ;
605
599
InjectParameters ( type , parameters ) ;
606
600
607
601
var obsolete = typeClass . GetCustomAttribute < ObsoleteAttribute > ( false ) ;
608
602
if ( obsolete != null )
609
603
{
610
- _log . Warn ( "{0} is obsolete. {1}" , typeName , obsolete . Message ) ;
604
+ _log . Warn ( "{0} is obsolete. {1}" , typeClass . AssemblyQualifiedName , obsolete . Message ) ;
611
605
}
612
606
return type ;
613
607
}
@@ -632,7 +626,7 @@ private static IType HeuristicType(System.Type resolvedType, string typeName, ID
632
626
var unwrapped = typeClass . UnwrapIfNullable ( ) ;
633
627
if ( unwrapped . IsEnum )
634
628
{
635
- return ( IType ) Activator . CreateInstance ( typeof ( EnumType < > ) . MakeGenericType ( unwrapped ) ) ;
629
+ return ( IType ) Activator . CreateInstance ( typeof ( EnumType < > ) . MakeGenericType ( unwrapped ) ) ;
636
630
}
637
631
638
632
if ( ! typeClass . IsSerializable )
@@ -641,7 +635,7 @@ private static IType HeuristicType(System.Type resolvedType, string typeName, ID
641
635
if ( length . HasValue )
642
636
return GetSerializableType ( typeClass , length . Value ) ;
643
637
644
- return GetSerializableType ( typeClass ) ;
638
+ return GetSerializedOrBasicType ( typeClass ) ;
645
639
}
646
640
647
641
/// <summary>
@@ -709,14 +703,19 @@ private static NullableType GetType(NullableType defaultUnqualifiedType, byte pr
709
703
/// </para>
710
704
/// </remarks>
711
705
public static NullableType GetSerializableType ( System . Type serializableType )
706
+ {
707
+ return ( NullableType ) GetSerializedOrBasicType ( serializableType ) ;
708
+ }
709
+
710
+ private static IType GetSerializedOrBasicType ( System . Type serializableType )
712
711
{
713
712
var key = serializableType . AssemblyQualifiedName ;
714
713
715
714
// The value factory may be run concurrently, but only one resulting value will be yielded to all threads.
716
715
// So we should add the type with its other key in a later operation in order to ensure we cache the same
717
716
// instance for both keys.
718
717
var added = false ;
719
- var type = ( NullableType ) typeByTypeOfName . GetOrAdd (
718
+ var type = typeByTypeOfName . GetOrAdd (
720
719
key ,
721
720
k =>
722
721
{
0 commit comments