question

BitSmithy-4663 avatar image
0 Votes"
BitSmithy-4663 asked ·

How to use field.GetCustomAttribute()

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
}






windows-uwp
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I updated title of my question and it lost code formating

0 Votes 0 ·

1 Answer

danielescipioni avatar image
0 Votes"
danielescipioni answered ·

Try with

Type type = typeof(Entry);
var properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
    Attribute a = property.GetCustomAttribute(typeof(DBFiledAtribute));
}
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.