Hangfire: can use [Display()] instead DisplayName

Created on 19 Sep 2017  路  3Comments  路  Source: HangfireIO/Hangfire

Hello .
I use [DisplayName("")] to change JobNameand it workes fine but I tried to Read Job Name from Resource file and for this I have to use [Display(name"",ResourceType=typeof())] but in this case it doesnt work .
I wonderd to know does it support[Diplay] attribute

question

All 3 comments

No, it doesn't. Would be supported if PR #993 is merged.

thank you . but My boss give me an idea .
create a custome Attribute Like below :

public class LocalizedDisplayNameAttribute : DisplayNameAttribute
    {
        public LocalizedDisplayNameAttribute( string resourceId)
            : base(GetMessageFromResource(resourceId))
        { }
    private static string GetMessageFromResource(string resourceId)
    {
        // TODO: Return the string from the resource file
    }
} `

then we need to use this attribute instead DisplayName .

Most of the attributes inside .NET BCL are sealed, so you cannot inherit from them. For example, DisplayAttribute you mentioned above is sealed.

But you're lucky, as DisplayNameAttribute is not. Not only that, its DisplayName property is virtual, so you can override it in the derived class.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abdelrady picture abdelrady  路  4Comments

jeffsugden picture jeffsugden  路  4Comments

cottsak picture cottsak  路  3Comments

plmwong picture plmwong  路  3Comments

tompazourek picture tompazourek  路  3Comments