Home

CallerMemberName

CallerMemberName is an attribute in the .NET framework and .NET Core defined in System.Runtime.CompilerServices. It enables a parameter to automatically receive the name of the caller member, simplifying scenarios such as implementing INotifyPropertyChanged and reducing reliance on hard-coded strings.

Usage typically involves applying the attribute to an optional string parameter, usually named propertyName, with a

Notes and behavior: The automatic substitution occurs only when the parameter is omitted; explicitly passing a

Related attributes include CallerLineNumber and CallerFilePath, which capture the caller’s line number and source file path,

default
value
of
null.
When
the
parameter
is
omitted
by
the
caller,
the
compiler
substitutes
the
name
of
the
calling
member.
For
example:
OnPropertyChanged([CallerMemberName]
string
propertyName
=
null)
{
...
}.
Calling
OnPropertyChanged()
from
inside
a
property
setter
will
supply
the
property’s
name
automatically.
value
overrides
the
automatic
result.
The
feature
is
most
useful
for
property
and
method
names
within
the
same
project
and
language.
It
is
commonly
used
to
raise
property
change
notifications
without
using
literal
strings,
thereby
aiding
refactoring
and
maintenance.
respectively.
Together,
these
attributes
provide
lightweight
metadata
about
call
sites
to
support
cleaner
and
more
maintainable
code.