Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When we had a requirement for deferred resource resolution we abandoned using the <code>MessageTemplateResourceName</code> and instead put our resource id as the <code>MessageTemplate</code> property. We then use that id later to look up the resource string value using the current culture. </p> <p>We standardized the naming convention for the id something like this: <code>RULESET_RULESETQUALIFIER_OPERATION_OBJECT_PROPERTY_VALIDATIONTYPE</code>. e.g. <code>RULESET_BMW_INSERT_CAR_YEAR_RANGE</code> or <code>RULESET_BMW_UPDATE_CAR_COLOR_LENGTH</code> etc.</p> <p>In the VAB configuration this would look something like:</p> <pre><code>&lt;property name="Color"&gt; &lt;validator lowerBound="0" lowerBoundType="Ignore" upperBound="50" upperBoundType="Inclusive" negated="false" messageTemplate="RULESET_BMW_INSERT_CAR_COLOR_LENGTH" messageTemplateResourceName="" messageTemplateResourceType="" tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="String Length Validator" /&gt; &lt;/property&gt; </code></pre> <p>The major downside is that you lose the ability to easily use the message template tokens to make the message slightly dynamic. This could be accomplished but the token values would have to be stored somewhere (e.g. you message class) so that they could be substituted later when the message string is evaluated.</p> <p>You may also want to consider creating multiple resource files for each of the audiences the messages are targeted for. That is, one resource for user messages and one for technical messages. So you could have UserMessages.resources, UserMessages.fr-BE.resources for the user messages. Then in another resource file duplicate the ids with different messages for logging (LogMessages.resources). That way you could have additional technical information for the log message. This might be overkill though.</p> <p>We then access the string values using the <code>ResourceManager</code>:</p> <pre><code>ResourceManager userResourceManager = new ResourceManager("UserMessages", Assembly.GetExecutingAssembly()); string userMessage = userResourceManager.GetString(resourceId); ResourceManager logResourceManager = new ResourceManager("LogMessages", Assembly.GetExecutingAssembly()); // Can also try to use InvariantCulture instead of "en" string messageToLog = logResourceManager.GetString(resourceId, new CultureInfo("en")); //alternative to ensure you get the english user message value: // string messageToLog = userResourceManager.GetString(resourceId, new CultureInfo("en")); </code></pre> <p><br /> You could abstract this away into a helper class or add it to your message class. You may also have to build some code to extract the ValidationResults and create message classes with the information you require.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload