Is it possible to use CallerMemberNameAttribute in f#

后端 未结 2 691
情书的邮戳
情书的邮戳 2020-12-17 17:02

The attribute and C# examples are noted here but it doesn\'t look to be possible for FSharp.

http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.

2条回答
  •  臣服心动
    2020-12-17 17:30

    A quick search through the compiler source code shows that the name CallerMemberName does not appear anywhere in the code, so I think this feature is not supported. (You can certainly mark a parameter with the attribute, but these attributes are special - they instruct the compiler instead of being discovered and used in some way at runtime.)

    Update July 2016: As of late June, F# now supports CallerLineNumber and CallerFilePath, but CallerMemberName is still absent. It seems like that one in particular is more difficult to implement, unfortunately.

    On a related note, F# has a few special identifiers that let you get the current source file name and line number, so you might be able to get similar information with __SOURCE_DIRECTORY__ and __LINE__
    (but not from the caller as in C#).

提交回复
热议问题