What do you think about the use of public static classes to hold on errorMessages and Ui button names, etc?
Example:
public static class UiMessages
{
public const string ConfirmationDialogTitle = "Atenção";
public const string Confirmati开发者_StackOverflowonLandOwnerDelete = "Você tem certeza que deseja deletar os proprietários selecionados?";
public const string ConfirmationProfessionalDelete = "Você tem certeza que deseja deletar os profissionais selecionados?";
public const string ConfirmationGnssDevice = "Você tem certeza que deseja deletar os aparelhos selecionados?";
}
Is this a bad pratice? Is there a better way to handle this?
In this case, I would say yes, it is bad practice -- because you likely want internationalization and localization expansion; you may be able to much better utilize properties or resources for such a task.
However, I use similar classes for internal-only (e.g. not displayed to the user) data such as names of data-columns.
In C#, use .resx files and make use of the built-in localization functions.
This should be of help:
http://www.c-sharpcorner.com/uploadfile/ankithakur/globalization_localization_in_dotnet_csharp07032006023510am/globalization_localization_in_dotnet_csharp.aspx
(Whoops, that's for ASP.NET).. try this:
http://msdn.microsoft.com/en-us/goglobal/bb688096.aspx
And a good example here:
http://msdn.microsoft.com/en-us/library/y99d1cd3(VS.71).aspx
.NET has localization and globalization support throughout, intended for just this kind of thing.
Hope that helps!
It's jut another way of defining global variables, and is just as good/bad as any other global variables.
Do these really need to be globally accessible? It would seem that each would only be needed in one class.
The only advance I can see is that you have all the string available in one place if you wanted to translate them into a different language, but that brings us into a whole different area.
精彩评论