Do you use resource file to store all the messages and globlal strings?

Updated by Tiago Araújo [SSW] 3 years ago. See history

123
No component provided for introEmbed

Store messages in the Message.resx

Catch(SqlNullValueException sqlex)
{
Response.Write("The value cannot be null.");
}

❌ Figure: Bad example - If you want to change the message, it will cost you lots of time to investigate every try-catch block

Catch(SqlNullValueException sqlex)
{
Response.Write(GetGlobalResourceObject("Messages", "SqlValueNotNull"));
}

😐 Figure: OK example - Better than the hard code, but still wordy

Catch(SqlNullValueException sqlex)
{
Response.Write(Resources.Messages.SqlValueNotNull); 'Good Code - storing message in resource file.
}

✅ Figure: Good example

Acknowledgements

Adam Cogan
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star