Try with
Type type = typeof(Entry);
var properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
Attribute a = property.GetCustomAttribute(typeof(DBFiledAtribute));
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I am traing to get custom atribute from a property. I use such code. But I don't want how to use
function: Attribute a = property.GetCustomAttribute(DBFiledAtribute);
Please help. My code is below:
Type type = typeof(Entry);
// get all all public properties.
PropertyInfo[] properties = type.GetProperties();
foreach (var property in properties)
{
Attribute a = property.GetCustomAttribute(DBFiledAtribute);//How to use this, How to get atribute from property
//do something with a
}
public class Entry : INotifyPropertyChanged
{
[DBFiledAtribute(DbFieldAtribute = "Id")]
public int Id {get; set;}
//rest of code
}
public class DBFiledAtribute : Attribute
{
public string DbFieldAtribute { get; set; }//Id, TimeStamp
}
Try with
Type type = typeof(Entry);
var properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
Attribute a = property.GetCustomAttribute(typeof(DBFiledAtribute));
}