I did not manage to get the OrmLite’s StringFilter to work.
However, after considering my options, I went with a RequestConverter
for
update requests, combined with an object dictionary as suggested:
private void ConfigureRequestConverters(Container container)
{
// trim all incoming string properties
RequestConverters.Add((req, requestDto) => {
if ((requestDto is IPost) || (requestDto is IPut))
{
var map = requestDto.ToObjectDictionary();
var map2 = new Dictionary<string, object>();
foreach (var kvp in map)
{
if (kvp.Value is string)
{
var str = ((string)kvp.Value).Trim();
map2.Add(kvp.Key, str);
}
}
// string properties trimmed?
if (map2.Count > 0)
{
map2.PopulateInstance(requestDto);
}
}
return Task.FromResult(requestDto);
});
}
After testing, I think this is a better approach, because it means the trimmed strings are also used in the RequestDto validations.
Please feel free to suggest any improvements to my code or approach.