C# 7 引入了本地函数(这太棒了!)。假设我有以下代码:
using System;
using PostSharp.Aspects;
namespace AspectCS7
{
class Program
{
private static void Main()
{
[MyAspect]
void LocalFunction()
{
Console.WriteLine("Hello Aspect!");
}
LocalFunction();
}
}
[Serializable]
public class MyAspect : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs args)
{
Console.WriteLine("Entering Aspect");
}
}
}
此代码显示编译时错误。是否可以将属性应用于局部函数?
局部函数一度允许使用属性。有一些网上的例子 https://asizikov.github.io/2016/04/15/thoughts-on-local-functions/使用属性的本地函数,但它们不再被允许。
更新:
以下是关于该主题的持续讨论:https://github.com/dotnet/csharplang/issues/794 https://github.com/dotnet/csharplang/issues/794.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)