@@ -55,9 +55,9 @@ public int GetHashCode((Type, Type[]) obj)
55
55
56
56
#if NET8_0_OR_GREATER
57
57
private static readonly ConcurrentDictionary < ( Type , Type [ ] ) , ConstructorInvoker > ConstructorInvokerByTypes =
58
- #else
59
- private static readonly ConcurrentDictionary < ( Type , Type [ ] ) , ConstructorInfo > ConstructorInfoByTypes =
58
+ new ( new TypesEqualityComparer ( ) ) ;
60
59
#endif
60
+ private static readonly ConcurrentDictionary < ( Type , Type [ ] ) , ConstructorInfo > ConstructorInfoByTypes =
61
61
new ( new TypesEqualityComparer ( ) ) ;
62
62
63
63
private static readonly ConcurrentDictionary < Type , Type [ ] > OrderedInterfaces = new ( ) ;
@@ -645,34 +645,49 @@ public static object Activate(this Type type, Type[] genericArguments, params ob
645
645
}
646
646
}
647
647
648
+ #if NET8_0_OR_GREATER
648
649
/// <summary>
649
- /// Gets the public constructor of type <paramref name="type"/>
650
+ /// Gets <see cref="ConstructorInvoker"/> of the public constructor of type <paramref name="type"/>
650
651
/// accepting specified <paramref name="argumentTypes"/>.
651
652
/// </summary>
652
653
/// <param name="type">The type to get the constructor for.</param>
653
654
/// <param name="argumentTypes">The arguments.</param>
654
655
/// <returns>
655
- /// Appropriate constructor, if a single match is found;
656
+ /// Appropriate constructor invoker , if a single match is found;
656
657
/// otherwise throws <see cref="InvalidOperationException"/>.
657
658
/// </returns>
658
659
/// <exception cref="InvalidOperationException">
659
660
/// The <paramref name="type"/> has no constructors suitable for <paramref name="argumentTypes"/>
660
661
/// -or- more than one such constructor.
661
662
/// </exception>
662
- #if NET8_0_OR_GREATER
663
- public static ConstructorInvoker GetSingleConstructorInvoker ( this Type type , Type [ ] argumentTypes ) =>
663
+ internal static ConstructorInvoker GetSingleConstructorInvoker ( this Type type , Type [ ] argumentTypes ) =>
664
664
ConstructorInvokerByTypes . GetOrAdd ( ( type , argumentTypes ) ,
665
665
static t => ConstructorExtractor ( t ) is ConstructorInfo ctor
666
666
? ConstructorInvoker . Create ( ctor )
667
667
: throw new InvalidOperationException ( Strings . ExGivenTypeHasNoOrMoreThanOneCtorWithGivenParameters ) ) ;
668
- #else
668
+
669
+ #endif
670
+ /// <summary>
671
+ /// Gets the public constructor of type <paramref name="type"/>
672
+ /// accepting specified <paramref name="argumentTypes"/>.
673
+ /// </summary>
674
+ /// <param name="type">The type to get the constructor for.</param>
675
+ /// <param name="argumentTypes">The arguments.</param>
676
+ /// <returns>
677
+ /// Appropriate constructor, if a single match is found;
678
+ /// otherwise throws <see cref="InvalidOperationException"/>.
679
+ /// </returns>
680
+ /// <exception cref="InvalidOperationException">
681
+ /// The <paramref name="type"/> has no constructors suitable for <paramref name="argumentTypes"/>
682
+ /// -or- more than one such constructor.
683
+ /// </exception>
669
684
public static ConstructorInfo GetSingleConstructor ( this Type type , Type [ ] argumentTypes ) =>
670
685
ConstructorInfoByTypes . GetOrAdd ( ( type , argumentTypes ) , ConstructorExtractor )
671
686
?? throw new InvalidOperationException ( Strings . ExGivenTypeHasNoOrMoreThanOneCtorWithGivenParameters ) ;
672
- #endif
673
687
688
+ #if NET8_0_OR_GREATER
674
689
/// <summary>
675
- /// Gets the public constructor of type <paramref name="type"/>
690
+ /// Gets <see cref="ConstructorInvoker"/> of the public constructor of type <paramref name="type"/>
676
691
/// accepting specified <paramref name="argumentTypes"/>.
677
692
/// </summary>
678
693
/// <param name="type">The type to get the constructor for.</param>
@@ -682,14 +697,24 @@ public static ConstructorInfo GetSingleConstructor(this Type type, Type[] argume
682
697
/// otherwise, <see langword="null"/>.
683
698
/// </returns>
684
699
[ CanBeNull ]
685
- #if NET8_0_OR_GREATER
686
- public static ConstructorInvoker GetSingleConstructorInvokerOrDefault ( this Type type , Type [ ] argumentTypes ) =>
700
+ internal static ConstructorInvoker GetSingleConstructorInvokerOrDefault ( this Type type , Type [ ] argumentTypes ) =>
687
701
ConstructorInvokerByTypes . GetOrAdd ( ( type , argumentTypes ) ,
688
702
static t => ConstructorExtractor ( t ) is ConstructorInfo ctor ? ConstructorInvoker . Create ( ctor ) : null ) ;
689
- #else
703
+
704
+ #endif
705
+ /// <summary>
706
+ /// Gets the public constructor of type <paramref name="type"/>
707
+ /// accepting specified <paramref name="argumentTypes"/>.
708
+ /// </summary>
709
+ /// <param name="type">The type to get the constructor for.</param>
710
+ /// <param name="argumentTypes">The arguments.</param>
711
+ /// <returns>
712
+ /// Appropriate constructor, if a single match is found;
713
+ /// otherwise, <see langword="null"/>.
714
+ /// </returns>
715
+ [ CanBeNull ]
690
716
public static ConstructorInfo GetSingleConstructorOrDefault ( this Type type , Type [ ] argumentTypes ) =>
691
717
ConstructorInfoByTypes . GetOrAdd ( ( type , argumentTypes ) , ConstructorExtractor ) ;
692
- #endif
693
718
694
719
private static readonly Func < ( Type , Type [ ] ) , ConstructorInfo > ConstructorExtractor = t => {
695
720
( var type , var argumentTypes ) = t ;
0 commit comments