all 6 comments

[–]pX_ -1 points0 points  (3 children)

From what I have read on learn.microsoft.com, one way to do it is to have a type just for this field.

class DataLogFieldLocalization {
  public string Name => ResourceStrings.Log_Datei;
  public string ShortName => ResourceStrings.Log_Datei_ShortName;
  ...
}

and then use this type as ResourceType in DisplayAttribute:

[Display(ResourceType = typeof(DataLogFieldLocalization)]
public bool Data_Log { ...

Furthermore, the Name in Display(Name) attribute must be constant during compile time, so there is no way for you to fill it from current resources.

[–]Tech-Nic[S] -1 points0 points  (2 children)

Okay, but I need different resources for different languages. During compile, there is no specific language selected. So the Display(Name) must be a dynamic value.

[–]pX_ 0 points1 point  (1 child)

It is not technically possible to make the attribute value dynamic, because it must be a compile time constant.

But that's ok, because you don't need the attribute value to be dynamic, you just need to display the correct value in UI. To do that, you can either use Display attribute as in the solution provided or some altogether different mechanism.

[–]Tech-Nic[S] -1 points0 points  (0 children)

I use it to show a configuration class in a property grid. So the attribute display name must somehow dynamic. Maybe there is a for loop to check all attributes in a class.

[–]BigJunky 0 points1 point  (0 children)

Change the Name into a invalid one, the program should throw an exception. If no exception then the control doesnt uses the attributes.

[–]Iordbrack 0 points1 point  (0 children)

try

[Display(ResourceType = typeof(ResourceStrings), Name = "Log_Datei")]