How to handle ASP.NET MVC global string constants

I have a new MVC 3 project, and in it I use model annotations, for example:

[DisplayFormat(NullDisplayText = "[Not set]")]

I prefer to avoid duplicating the string literal using something like this:

[DisplayFormat(NullDisplayText =  GlobalStrings.Nulls.DefaultNullText)]

Where:

public struct GlobalStrings
{
    public struct Nulls
    {
        public const string DefaultNullText = "[Not set]";
    }
}

But I can't help but feel that there is a better way to do this?

+3
source share
1 answer

What you do is not terribly bad - you share your constants in one easily changeable place, which is a very good idea.

GlobalStrings , ( ). ( , , ApplicationName Publisher).

(, ). simlar- "" . , . "" , , , . , " " , DataAccess , , const/ DataAccess, "global" DataAccess.DefaultNullString - , .

, "", "" ( " , , " )

, /, GlobalStrings .

+6

Source: https://habr.com/ru/post/1779750/


All Articles