Hi,
i have seen some of the INotifyPropertyChanged member method using [CallerMemberName] as a method argument prefix. i want to know how actually it works. how to do some this similar to it? can any one explain me please?
Note:
I have already read some of the
links [
^]where we can find some additional improvements in .net4.5 regarding attribute usage. please let me know some links other than similar to this :)
My Custom attribute class
namespace AttributeTesting
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public class CallerMember : Attribute
{
public string ParameterName { get; set; }
}
}
Implemented employeeClass
namespace AttributeTesting.Data
{
[CallerMember]
public class EmployeeData : INotifyPropertyChanged
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; OnPropertyChanged(); }
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMember] string ParameterName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(ParameterName));
}
}
#endregion
}
}
try to make it work
namespace AttributeTesting
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += OnMainWindowLoaded;
}
void OnMainWindowLoaded(object sender, RoutedEventArgs e)
{
EmployeeData EmployeeData = new EmployeeData { Name = "GoldCoin" };
}
}
}
Unable to implement my custom attribute. what should i do next
Note:
I am trying to implement something that .net 4.5 has. The same in my solution which was developed in .net 4.0 :)