Reputation: 4012
public class MainViewModel
{
[Save]
public String Name { get; set; }
public MainViewModel()
{
Name = "qwe asd zxc";
LoadProperties(this);
}
public void LoadProperties(object viewModel)
{
var properties = viewModel.GetType().GetCustomAttributes(typeof(Save),false);
}
}
public class Save : Attribute{}
the properties variable in the load properties method has 0 item What did i do wrong?
Upvotes: 0
Views: 156
Reputation: 116168
This should work
var properties = viewModel.GetType()
.GetProperties()
.Where(p => p.GetCustomAttributes(typeof(Save),false).Any())
.ToArray();
Upvotes: 3