Skip to content

Commit 0916784

Browse files
committed
Refactor AnonymousConstructorDescriptor formatting & docs
Reformatted code to use file-scoped namespace and moved using directives outside the namespace. Improved and expanded XML documentation for the struct and its constructor. Minor readability refactor in the constructor; no functional changes to logic or behavior. Changes are focused on code style, formatting, and documentation clarity.
1 parent c179ee9 commit 0916784

1 file changed

Lines changed: 60 additions & 61 deletions

File tree

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,73 @@
1-
namespace BionicCode.Utilities.Net.Reflection
2-
{
3-
using System;
4-
using System.Reflection;
1+
namespace BionicCode.Utilities.Net.Reflection;
2+
3+
using System;
4+
using System.Reflection;
55

6+
/// <summary>
7+
/// A descriptor that provides information about an anonymous constructor (where the caller does not have a direct <see cref="ConstructorInfo"/> representation of the constructor symbol).
8+
/// </summary>
9+
/// <remarks>The <see cref="AnonymousConstructorDescriptor"/> is used to provide information for anonymous constructor symbols, which is when the caller does not have the direct <see cref="ConstructorInfo"/> representation.
10+
/// <para/>When the caller has the direct <see cref="ConstructorInfo"/> representation and the constructor is well-known, use the <see cref="WellKnownConstructorDescriptor"/> instead.
11+
/// <para/>Important: well-known descriptors are preferred over anonymous descriptors when the <see cref="ConstructorInfo"/> is available to ensure maximum accuracy and performance.
12+
/// </remarks>
13+
internal readonly struct AnonymousConstructorDescriptor : IEquatable<AnonymousConstructorDescriptor>
14+
{
615
/// <summary>
7-
/// A descriptor that provides information about an anonymous constructor (where the caller does not have a direct <see cref="ConstructorInfo"/> representation of the constructor symbol).
16+
/// Initializes a new instance of the <see cref="AnonymousConstructorDescriptor"/> struct.
817
/// </summary>
9-
/// <remarks>The <see cref="AnonymousConstructorDescriptor"/> is used to provide information for anonymous constructor symbols, which is when the caller does not have the direct <see cref="ConstructorInfo"/> representation.
10-
/// <para/>When the caller has the direct <see cref="ConstructorInfo"/> representation and the constructor is well-known, use the <see cref="WellKnownConstructorDescriptor"/> instead.
11-
/// <para/>Important: well-known descriptors are preferred over anonymous descriptors when the <see cref="ConstructorInfo"/> is available to ensure maximum accuracy and performance.
18+
/// <remarks>The <see cref="AnonymousConstructorDescriptor"/> is used to provide information about a constructor symbol of which the caller does not have a direct <see cref="ConstructorData"/> representation and instead only signature information is available.
19+
/// <para/>For best accuracy and performance always use the <see cref="WellKnownConstructorDescriptor"/>, which requires the caller to have direct access to the <see cref="MethodInfo"/> or <see cref="ConstructorInfo"/> representation of the method or constructor.
1220
/// </remarks>
13-
internal readonly struct AnonymousConstructorDescriptor : IEquatable<AnonymousConstructorDescriptor>
21+
/// <param name="declaringTypeHandle">The runtime type handle representing the declaring type of the anonymous constructor.</param>
22+
/// <param name="constructorParameters">The list of parameters for the anonymous method. Can be <see cref="MethodParameterInfoList.Empty"/> or <see langword="null"/> to indicate no parameters.</param>
23+
/// <returns>A new instance of <see cref="AnonymousConstructorDescriptor"/> representing the specified anonymous method.</returns>
24+
/// <exception cref="ArgumentNullException">Thrown when
25+
/// <list type="bullet">
26+
/// <item><paramref name="declaringTypeHandle"/> is <see langword="default"/>.</item>
27+
/// <item>the provided <paramref name="declaringTypeHandle"/> does not resolve to a runtime type.</item>
28+
/// </list>
29+
/// </exception>
30+
public AnonymousConstructorDescriptor(
31+
RuntimeTypeHandle declaringTypeHandle,
32+
MethodParameterInfoList? constructorParameters)
1433
{
15-
/// <summary>
16-
/// Initializes a new instance of the <see cref="AnonymousConstructorDescriptor"/> struct.
17-
/// </summary>
18-
/// <remarks>The <see cref="AnonymousConstructorDescriptor"/> is used to provide information about a constructor symbol of which the caller does not have a direct <see cref="ConstructorData"/> representation and instead only signature information is available.
19-
/// <para/>For best accuracy and performance always use the <see cref="WellKnownConstructorDescriptor"/>, which requires the caller to have direct access to the <see cref="MethodInfo"/> or <see cref="ConstructorInfo"/> representation of the method or constructor.
20-
/// </remarks>
21-
/// <param name="declaringTypeHandle">The runtime type handle representing the declaring type of the anonymous constructor.</param>
22-
/// <param name="constructorParameters">The list of parameters for the anonymous method. Can be <see cref="MethodParameterInfoList.Empty"/> or <see langword="null"/> to indicate no parameters.</param>
23-
/// <returns>A new instance of <see cref="AnonymousConstructorDescriptor"/> representing the specified anonymous method.</returns>
24-
/// <exception cref="ArgumentNullException">Thrown when
25-
/// <list type="bullet">
26-
/// <item><paramref name="declaringTypeHandle"/> is <see langword="default"/>.</item>
27-
/// <item>the provided <paramref name="declaringTypeHandle"/> does not resolve to a runtime type.</item>
28-
/// </list>
29-
/// </exception>
30-
public AnonymousConstructorDescriptor(
31-
RuntimeTypeHandle declaringTypeHandle,
32-
MethodParameterInfoList? constructorParameters)
33-
{
34-
ArgumentNullExceptionAdvanced.ThrowIfDefault(declaringTypeHandle);
35-
Type? declaringType = Type.GetTypeFromHandle(declaringTypeHandle);
36-
ArgumentNullExceptionAdvanced.ThrowIfNull(
37-
declaringType,
38-
nameof(declaringTypeHandle),
39-
$"Invalid argument '{nameof(declaringTypeHandle)}'. The provided declaring type handle does not resolve to a runtime type.");
34+
ArgumentNullExceptionAdvanced.ThrowIfDefault(declaringTypeHandle);
35+
var declaringType = Type.GetTypeFromHandle(declaringTypeHandle);
36+
ArgumentNullExceptionAdvanced.ThrowIfNull(
37+
declaringType,
38+
nameof(declaringTypeHandle),
39+
$"Invalid argument '{nameof(declaringTypeHandle)}'. The provided declaring type handle does not resolve to a runtime type.");
4040

41-
DeclaringTypeHandle = declaringTypeHandle;
42-
ConstructorParameterList = constructorParameters.OrEmpty();
43-
IsAnonymous = true;
44-
}
41+
DeclaringTypeHandle = declaringTypeHandle;
42+
ConstructorParameterList = constructorParameters.OrEmpty();
43+
IsAnonymous = true;
44+
}
4545

46-
public RuntimeTypeHandle DeclaringTypeHandle { get; }
47-
public MethodParameterInfoList ConstructorParameterList { get; }
48-
public bool IsAnonymous { get; }
46+
public RuntimeTypeHandle DeclaringTypeHandle { get; }
47+
public MethodParameterInfoList ConstructorParameterList { get; }
48+
public bool IsAnonymous { get; }
4949

50-
public bool Equals(AnonymousConstructorDescriptor other)
51-
=> DeclaringTypeHandle.Equals(other.DeclaringTypeHandle)
52-
&& ConstructorParameterList.Equals(other.ConstructorParameterList)
53-
&& IsAnonymous == other.IsAnonymous;
50+
public bool Equals(AnonymousConstructorDescriptor other)
51+
=> DeclaringTypeHandle.Equals(other.DeclaringTypeHandle)
52+
&& ConstructorParameterList.Equals(other.ConstructorParameterList)
53+
&& IsAnonymous == other.IsAnonymous;
5454

55-
public override int GetHashCode()
56-
{
57-
var hashCode = new HashCode();
58-
hashCode.Add(DeclaringTypeHandle);
59-
hashCode.Add(ConstructorParameterList);
60-
hashCode.Add(IsAnonymous);
61-
hashCode.Add(DeclaringTypeHandle);
55+
public override int GetHashCode()
56+
{
57+
var hashCode = new HashCode();
58+
hashCode.Add(DeclaringTypeHandle);
59+
hashCode.Add(ConstructorParameterList);
60+
hashCode.Add(IsAnonymous);
61+
hashCode.Add(DeclaringTypeHandle);
6262

63-
return hashCode.ToHashCode();
64-
}
63+
return hashCode.ToHashCode();
64+
}
6565

66-
public static bool operator ==(AnonymousConstructorDescriptor left, AnonymousConstructorDescriptor right)
67-
=> left.Equals(right);
68-
public static bool operator !=(AnonymousConstructorDescriptor left, AnonymousConstructorDescriptor right)
69-
=> !(left == right);
66+
public static bool operator ==(AnonymousConstructorDescriptor left, AnonymousConstructorDescriptor right)
67+
=> left.Equals(right);
68+
public static bool operator !=(AnonymousConstructorDescriptor left, AnonymousConstructorDescriptor right)
69+
=> !(left == right);
7070

71-
public override bool Equals(object obj)
72-
=> obj is AnonymousConstructorDescriptor other && Equals(other);
73-
}
71+
public override bool Equals(object obj)
72+
=> obj is AnonymousConstructorDescriptor other && Equals(other);
7473
}

0 commit comments

Comments
 (0)