Skip to content

Commit 9b87a26

Browse files
committed
Refactor TypeData to use direct Type property, add explicit impls
Refactor TypeData and related reflection utilities to use a direct Type property instead of UnwrapType(), improving clarity and performance. Add caching and accessors for explicit interface implementations (properties, methods, events) in TypeData. Improve explicit interface implementation detection in MethodData with a new mapping cache. Update documentation and clean up code for better maintainability and efficiency.
1 parent 120a532 commit 9b87a26

19 files changed

Lines changed: 496 additions & 328 deletions

‎src/BionicCode.Utilities.Net.Common/Exception/ArgumentExceptionHelpers.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ internal static void ThrowIfEventHandlerNotAssignable([NotNull] Delegate clientH
326326

327327
for (int parameterIndex = 0; parameterIndex < eventDelegateParameters.Count; parameterIndex++)
328328
{
329-
Type eventDelegateParameterType = eventDelegateParameters[parameterIndex].ParameterTypeData.UnwrapType();
329+
Type eventDelegateParameterType = eventDelegateParameters[parameterIndex].ParameterTypeData.Type;
330330
Type eventHandlerParameterType = clientHandlerParameters[parameterIndex].ParameterType;
331331
if (!eventHandlerParameterType.IsAssignableFrom(eventDelegateParameterType))
332332
{

‎src/BionicCode.Utilities.Net.Common/ProxyEventHandlerGenerator.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static Delegate GenerateProxy(ParameterList eventHandlerParameters, Type
3838
var expressionParameters = new List<ParameterExpression>();
3939
foreach (ParameterData parameter in eventHandlerParameters)
4040
{
41-
ParameterExpression expressionParameter = Expression.Parameter(parameter.ParameterTypeData.UnwrapType(), parameter.Name);
41+
ParameterExpression expressionParameter = Expression.Parameter(parameter.ParameterTypeData.Type, parameter.Name);
4242
expressionParameters.Add(expressionParameter);
4343
}
4444

@@ -49,7 +49,7 @@ private static Delegate GenerateProxy(ParameterList eventHandlerParameters, Type
4949
if (lastParameter.IsParams)
5050
{
5151
IEnumerable<Expression> paramsParameterArguments = expressionParameters.Skip(lastParameter.GetParameterInfo().Position)
52-
.Select(parameter => Expression.TypeAs(parameter, lastParameter.ParameterTypeData.UnwrapType().GetElementType()))
52+
.Select(parameter => Expression.TypeAs(parameter, lastParameter.ParameterTypeData.Type.GetElementType()))
5353
.Cast<Expression>();
5454
NewArrayExpression argsArray = Expression.NewArrayInit(typeof(object), paramsParameterArguments);
5555
delegateParameters.RemoveRange(lastParameter.Position, expressionParameters.Count - lastParameter.Position);
@@ -70,7 +70,7 @@ private static Delegate GenerateProxy(ParameterList eventHandlerParameters, Type
7070
throw;
7171
}
7272

73-
Type eventDelegateType = eventDelegateTypeData.UnwrapType();
73+
Type eventDelegateType = eventDelegateTypeData.Type;
7474
Delegate proxyEventSourceHandler = Expression.Lambda(eventDelegateType, method, expressionParameters).Compile();
7575

7676
return proxyEventSourceHandler;

‎src/BionicCode.Utilities.Net.Profiling/AttributeProfiler.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ private void GetTargetMethods(TypeData typeDataToProfile, bool isFindInstancePro
620620

621621
MethodInfo methodInfo = methodData.GetMethodInfo();
622622
bool isMethodStatic = methodData.IsStatic;
623-
bool isFactoryMethod = isMethodStatic && typeDataToProfile.UnwrapType().IsAssignableFrom(methodData.ReturnTypeData.UnwrapType());
623+
bool isFactoryMethod = isMethodStatic && typeDataToProfile.Type.IsAssignableFrom(methodData.ReturnTypeData.Type);
624624
if (isFindInstanceProviderEnabled
625625
&& !hasHighPriorityInstanceProvider
626626
&& isFactoryMethod)
@@ -754,7 +754,7 @@ private void GetTargetProperties(TypeData typeDataToProfile, bool isFindInstance
754754
&& !hasHighPriorityInstanceProvider
755755
&& isPropertyStatic
756756
&& propertyData.CanRead
757-
&& typeDataToProfile.UnwrapType().IsAssignableFrom(propertyData.PropertyTypeData.UnwrapType()))
757+
&& typeDataToProfile.Type.IsAssignableFrom(propertyData.PropertyTypeData.Type))
758758
{
759759
ProfilerFactoryAttribute profilerFactoryAttribute = propertyInfo.GetCustomAttribute<ProfilerFactoryAttribute>(false);
760760
hasHighPriorityInstanceProvider = profilerFactoryAttribute != null;
@@ -823,7 +823,7 @@ private void GetInstanceProviderField(TypeData typeDataToProfile, CancellationTo
823823
FieldInfo fieldInfo = fieldData.GetFieldInfo();
824824
if (fieldData.IsStatic
825825
&& !hasHighPriorityInstanceProvider
826-
&& typeDataToProfile.UnwrapType().IsAssignableFrom(fieldData.FieldTypeData.UnwrapType()))
826+
&& typeDataToProfile.Type.IsAssignableFrom(fieldData.FieldTypeData.Type))
827827
{
828828
hasHighPriorityInstanceProvider = fieldInfo.GetCustomAttribute<ProfilerFactoryAttribute>(false) != null;
829829
if (hasHighPriorityInstanceProvider || instanceProviderInfo is null)

‎src/BionicCode.Utilities.Reflection/ConstructorListBuilder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal static ConstructorList Create(IEnumerable<ConstructorInfo>? items)
5858
internal static ConstructorList Create(TypeData declaringTypeData)
5959
{
6060
ArgumentNullException.ThrowIfNull(declaringTypeData);
61-
return CreateInternal(declaringTypeData.UnwrapType());
61+
return CreateInternal(declaringTypeData.Type);
6262
}
6363

6464
internal static ConstructorList Create(Type declaringType)

0 commit comments

Comments
 (0)