C # 7 Local functions: are attributes / aspects allowed?

C # 7 introduced local functions (which is great!). Suppose I have the following code:

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"); } } } 

This code shows compile-time errors. Can attributes be applied to local functions?

+6
source share
1 answer

Attributes were allowed for local functions at one point. There are several examples of local functions using attributes on the Internet, however they are no longer allowed.

Update: Here is the current discussion on this topic: https://github.com/dotnet/csharplang/issues/794 .

0
source

Source: https://habr.com/ru/post/1266922/


All Articles