Skip to content

Commit 73d0fda

Browse files
committed
GetSingleConstructorInvokerOrDefault/GetSingleConstructorInvoker changes
- made them internal - make them additonal to existing counterparts - add summaries
1 parent ccbcd4a commit 73d0fda

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

Orm/Xtensive.Orm/Reflection/TypeHelper.cs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public int GetHashCode((Type, Type[]) obj)
5555

5656
#if NET8_0_OR_GREATER
5757
private static readonly ConcurrentDictionary<(Type, Type[]), ConstructorInvoker> ConstructorInvokerByTypes =
58-
#else
59-
private static readonly ConcurrentDictionary<(Type, Type[]), ConstructorInfo> ConstructorInfoByTypes =
58+
new(new TypesEqualityComparer());
6059
#endif
60+
private static readonly ConcurrentDictionary<(Type, Type[]), ConstructorInfo> ConstructorInfoByTypes =
6161
new(new TypesEqualityComparer());
6262

6363
private static readonly ConcurrentDictionary<Type, Type[]> OrderedInterfaces = new();
@@ -645,34 +645,49 @@ public static object Activate(this Type type, Type[] genericArguments, params ob
645645
}
646646
}
647647

648+
#if NET8_0_OR_GREATER
648649
/// <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"/>
650651
/// accepting specified <paramref name="argumentTypes"/>.
651652
/// </summary>
652653
/// <param name="type">The type to get the constructor for.</param>
653654
/// <param name="argumentTypes">The arguments.</param>
654655
/// <returns>
655-
/// Appropriate constructor, if a single match is found;
656+
/// Appropriate constructor invoker, if a single match is found;
656657
/// otherwise throws <see cref="InvalidOperationException"/>.
657658
/// </returns>
658659
/// <exception cref="InvalidOperationException">
659660
/// The <paramref name="type"/> has no constructors suitable for <paramref name="argumentTypes"/>
660661
/// -or- more than one such constructor.
661662
/// </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) =>
664664
ConstructorInvokerByTypes.GetOrAdd((type, argumentTypes),
665665
static t => ConstructorExtractor(t) is ConstructorInfo ctor
666666
? ConstructorInvoker.Create(ctor)
667667
: 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>
669684
public static ConstructorInfo GetSingleConstructor(this Type type, Type[] argumentTypes) =>
670685
ConstructorInfoByTypes.GetOrAdd((type, argumentTypes), ConstructorExtractor)
671686
?? throw new InvalidOperationException(Strings.ExGivenTypeHasNoOrMoreThanOneCtorWithGivenParameters);
672-
#endif
673687

688+
#if NET8_0_OR_GREATER
674689
/// <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"/>
676691
/// accepting specified <paramref name="argumentTypes"/>.
677692
/// </summary>
678693
/// <param name="type">The type to get the constructor for.</param>
@@ -682,14 +697,24 @@ public static ConstructorInfo GetSingleConstructor(this Type type, Type[] argume
682697
/// otherwise, <see langword="null"/>.
683698
/// </returns>
684699
[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) =>
687701
ConstructorInvokerByTypes.GetOrAdd((type, argumentTypes),
688702
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]
690716
public static ConstructorInfo GetSingleConstructorOrDefault(this Type type, Type[] argumentTypes) =>
691717
ConstructorInfoByTypes.GetOrAdd((type, argumentTypes), ConstructorExtractor);
692-
#endif
693718

694719
private static readonly Func<(Type, Type[]), ConstructorInfo> ConstructorExtractor = t => {
695720
(var type, var argumentTypes) = t;

0 commit comments

Comments
 (0)