Skip to content

Commit 4d508bd

Browse files
committed
add NewSlot attribute
1 parent 3623e9c commit 4d508bd

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/AspectCore.Core/Utils/ProxyGeneratorUtils.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,22 @@ internal static MethodBuilder DefineClassMethod(MethodInfo method, Type implType
441441

442442
if (method.Attributes.HasFlag(MethodAttributes.Public))
443443
{
444-
attributes = attributes | MethodAttributes.Public;
444+
attributes |= MethodAttributes.Public;
445445
}
446446

447447
if (method.Attributes.HasFlag(MethodAttributes.Family))
448448
{
449-
attributes = attributes | MethodAttributes.Family;
449+
attributes |= MethodAttributes.Family;
450450
}
451451

452452
if (method.Attributes.HasFlag(MethodAttributes.FamORAssem))
453453
{
454-
attributes = attributes | MethodAttributes.FamORAssem;
454+
attributes |= MethodAttributes.FamORAssem;
455+
}
456+
457+
if (method.Attributes.HasFlag(MethodAttributes.NewSlot))
458+
{
459+
attributes |= MethodAttributes.NewSlot;
455460
}
456461

457462
var methodBuilder = DefineMethod(method, method.Name, attributes, implType, typeDesc);
@@ -470,6 +475,9 @@ private static MethodBuilder DefineMethod(MethodInfo method, string name, Method
470475
//inherit targetMethod's attribute
471476
foreach (var customAttributeData in method.CustomAttributes)
472477
{
478+
if (customAttributeData.AttributeType.Name == "PreserveBaseOverridesAttribute")
479+
continue; // Skip PreserveBaseOverridesAttribute as it is not needed in dynamic proxy generation.
480+
473481
methodBuilder.SetCustomAttribute(CustomAttributeBuilderUtils.DefineCustomAttribute(customAttributeData));
474482
}
475483

tests/AspectCore.Tests/DynamicProxy/CovariantReturnTypesTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using AspectCore.DynamicProxy;
1+
using System.Reflection;
2+
using AspectCore.DynamicProxy;
23
using Xunit;
34

45
namespace AspectCore.Tests.DynamicProxy;
@@ -13,8 +14,8 @@ public interface IService
1314

1415
public class Service : IService
1516
{
16-
public virtual object Method() => nameof(Service);
17-
public virtual object Property { get; } = nameof(Service);
17+
public virtual object Method() => new();
18+
public virtual object Property { get; } = new();
1819
}
1920

2021
public class CovariantReturnsService : Service

0 commit comments

Comments
 (0)