Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

特殊场景:创建接口实现类时,覆盖了c# 8.0 的接口默认实现方法 #223

Open
fs7744 opened this issue Apr 30, 2020 · 6 comments
Assignees
Labels

Comments

@fs7744
Copy link
Contributor

fs7744 commented Apr 30, 2020

该场景特殊,一般aop 使用场景应该佷难遇见

https://github.com/dotnetcore/AspectCore-Framework/blob/master/src/AspectCore.Core/Utils/ProxyGeneratorUtils.cs#L365

应该判断 method.IsAbstract

if (method.IsAbstract)
            {
                var methodBuilder = implTypeBuilder.DefineMethod(method.Name, InterfaceMethodAttributes,
                    method.CallingConvention, method.ReturnType,
                    method.GetParameters().Select(x => x.ParameterType).ToArray());
                var ilGen = methodBuilder.GetILGenerator();
                if (method.ReturnType != typeof(void))
                {
                    ilGen.EmitDefault(method.ReturnType);
                }
                ilGen.Emit(OpCodes.Ret);
                implTypeBuilder.DefineMethodOverride(methodBuilder, method);
            }
@huoshan12345
Copy link
Collaborator

@fs7744 能否提供一些复现的案例,你说的覆盖具体是指怎么覆盖了

@hjkl950217
Copy link
Contributor

插眼

@fs7744
Copy link
Contributor Author

fs7744 commented Jan 21, 2021

时间太久了,要不是有人提醒,都已经忘了这个issue了,
当时应该是上面那段代码所示,
有使用接口默认方法的场景都会被替换为代理类中的实现的方法,

@huayh
Copy link

huayh commented Jun 2, 2022

是如何解决的呢?我现在也遇到了这个问题

@huoshan12345
Copy link
Collaborator

huoshan12345 commented Feb 28, 2025

本来我一直想着修的, 结果一转眼就过了好几年 ( 悲 )

不知道是不是楼主说的情况: #332

@fs7744
Copy link
Contributor Author

fs7744 commented Mar 1, 2025

👍
应该是,记忆有些模糊了,哈哈哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants