I am using a sample project for Entity Framework Audit Trail from here
The problem is we are already using .NET 4.0 in our project but this sample is using .NET 4.5.
Can somebody tell me what is the equivalent of GetCustomAttribute in .NET 4,
Below is my code:
private static string ColumnNameFactory(this Type type, string propertyName)
{
string columnName = propertyName;
Type entityType = type.GetEntityType();
var columnAttribute = entityType.GetProperty(propertyName).GetCustomAttribute<ColumnAttribute>(false);
if (columnAttribute != null && !string.IsNullOrEmpty(columnAttribute.Name))
{
columnName = columnAttribute.Name;
}
return columnName;
}
In this code: GetCustomAttribute is not recognized.
MemberInfo.GetCustomAttribute<T>() belongs to the CustomAttributeExtensions extension class which contains very thin wrappers to Attribute.GetCustomAttribute() and Attribute.GetCustomAttributes(). These wrappers cast the returned Attribute to the expected attribute type. See the reference source here: https://referencesource.microsoft.com/#mscorlib/system/reflection/CustomAttributeExtensions.cs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With