If this method is called in C# 5 without specifying the optional parameters, the compiler will insert the file name, line number, and containing member name instead of the default values. If it’s called in older languages that don’t support optional parameters, those languages will pass the default values, like any other optional method.

These features look trivial at first glance. However, like most features, they are actually more complicated to design in a solid and robust fashion. Here are some of the less obvious issues that the C# team needed to deal with when creating this feature:

Disclaimer: I am basing these posts entirely on logical deduction. I do not have access to a specification or implementation of this feature; all I know is what Anders announced in his //Build/ presentation. However, the C# team would have needed to somehow deal with each of thee issues. Since these attributes are not yet supported by any public CTP, I can’t test my assumptions

To start with, they needed to create new compiler errors if the attribute is applied to an incorrectly-typed parameter, or a non-optional parameter. Creating compiler errors is expensive; they need to be documented, tested, and localized into every language supported by C#.

The attributes should perhaps support nullable types, or parameter types with custom implicit conversions to int or string. (especially long or short)

If a method with these attributes is called in an expression tree literal (a lambda expression converted to an Expression<TDelegate>), the compiler would need to insert ConstantExpressions with the actual line number or other info to pass as the parameter.

In addition to being supported in methods, the attributes should also be supported on parameters for delegate types, allowing you to write

[CallerFilePath] seems fairly simple. Any function call must happen in source code, in a source file that has a path. However, it needs to take into account #line directives, so that, for example, it will work as expected in Razor views. I don’t know what it does inside #line hidden, in which there isn’t a source file.