.NET 4.0 equivalent to GetCustomAttribute

I am using a sample project to audit an Entity Framework entity from here

The problem is that we are already using .NET 4.0 in our project, but this example is using .NET 4.5.

Can someone tell me what is equivalent 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: is GetCustomAttribute

not recognized.

+3


source to share


1 answer


+3


source







All Articles