55using System . Linq ;
66using System . Reflection ;
77using System . Text ;
8+ using System . Text . RegularExpressions ;
89
910namespace clojure . lang . TypeName2 ;
1011
@@ -816,6 +817,19 @@ public Type Resolve(
816817 else
817818 type = asm . GetType ( _name . DisplayName , false , ignoreCase ) ;
818819
820+ if ( type is null )
821+ {
822+ var arityName = MaybeAddBackquoteArity ( _name ) ;
823+ if ( ! arityName . Equals ( _name . DisplayName ) )
824+ {
825+ if ( typeResolver is not null )
826+ type = typeResolver ( asm , arityName , ignoreCase ) ;
827+ else
828+ type = asm . GetType ( arityName , false , ignoreCase ) ;
829+ }
830+ }
831+
832+
819833 if ( type is null )
820834 {
821835 if ( throwOnError )
@@ -827,7 +841,8 @@ public Type Resolve(
827841 {
828842 foreach ( var n in _nested )
829843 {
830- var tmp = type . GetNestedType ( n . DisplayName , BindingFlags . Public | BindingFlags . NonPublic ) ;
844+ var nestedName = MaybeAddBackquoteArity ( n ) ;
845+ var tmp = type . GetNestedType ( nestedName , BindingFlags . Public | BindingFlags . NonPublic ) ;
831846 if ( tmp is null )
832847 {
833848 if ( throwOnError )
@@ -888,6 +903,16 @@ private static Type DefaultTypeResolver(Assembly assembly, string typename, Name
888903 return type ;
889904 }
890905
906+ Regex _backquoteArityRegex = new ( @"^.*`\d*$" , RegexOptions . Compiled ) ;
907+
908+ private string MaybeAddBackquoteArity ( IClrTypeIdentifier name )
909+ {
910+ if ( name . ImplicitGenericCount > 0 && ! _backquoteArityRegex . IsMatch ( name . DisplayName ) )
911+ return $ "{ name . DisplayName } `{ name . ImplicitGenericCount } ";
912+ else
913+ return name . DisplayName ;
914+ }
915+
891916 #endregion
892917
893918
@@ -906,17 +931,6 @@ public static Type GetTypeFromName(string name, Namespace ns = null)
906931 }
907932
908933
909- // public static Type GetTypeFromName(string name, Namespace ns = null)
910- // {
911- // ClrTypeSpec2 spec = Parse(name);
912- // if (spec == null)
913- // return null;
914- // return spec.Resolve(
915- // ns,
916- // name,
917- // assyName => Assembly.Load(assyName));
918- // }
919-
920934 #endregion
921935
922936}
0 commit comments