mscorlib 4.0.0.0 System.Attribute System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)

You apply the CallerMemberName attribute to an optional parameter that has a default value. You must specify an explicit default value for the optional parameter. You can't apply this attribute to parameters that aren't specified as optional.

For more information, see Caller Information (C# and Visual Basic).

You can use the CallerMemberName attribute to avoid specifying the member name as a String argument to the called method. By using this technique, you avoid the problem that Rename Refactoring doesn't change the String values. This is especially useful for the following tasks:

Using tracing and diagnostic routines.

Implementing the interface when binding data. This interface allows the property of an object to notify a bound control that the property has changed, so that the control can display the updated information. Without the CallerMemberName attribute, you must specify the property name as a literal.

The following chart shows the member names that are returned when you use the CallerMemberName attribute.

Call occurs within

Member name result

Method, property, or event

The name of the method, property, or event from which the call originated.

Constructor

The string ".ctor"

Static constructor

The string ".cctor"

Destructor

The string "Finalize"

User-defined operators or conversions

The generated name for the member, for example, "op_Addition".

Attribute constructor

The name of the member to which the attribute is applied. If the attribute is any element within a member (such as a parameter, a return value, or a generic type parameter), this result is the name of the member that's associated with that element.

No containing member (for example, assembly-level or attributes applied to types)

The default value of the optional parameter.

Allows you to obtain the method or property name of the caller to the method.

- Constructor
  4.0.0.0
  To be added.

  Initializes a new instance of the class.