Closed jwaliszko closed 9 years ago
I've just unlocked default types parsing: https://github.com/JaroslawWaliszko/ExpressiveAnnotations/commit/ee4e63fae6eb26e989b8e3d12a62cc27ef84d3d8
It was actually no more than that (at least for now it is enough I think):
tryParse: function(value, type) {
switch (type) {
case 'datetime':
...
default:
try {
return JSON.parse(value);
} catch (ex) {
return { error: true, msg: 'Given value was not recognized as valid JSON.' };
}
}
Thanks to https://github.com/webwizgordon for help.
That case is directly related to this thread (more context there).
Basic idea: simplify the support of arrays in the following manner:
1st option
I was thinking about something like that, although I'm not fully aware of all pros/cons of such a solution yet:
to be delivered by ExpressiveAnnotations:
js:
c#:
to be done by developers:
Then, anyone who would like to use that built-in array type, should provide appropriate DOM field from where it can be extracted (like in any other case), but this time using templates, since there is no out-of-the-box construction in ASP.MVC for that, so create:
/Type/ArrayTemplate.cshtml:
and put this in the form:
then, respective
ArrayContains
function, e.g.IntArrayContains
(not necesairly built-in) would work:for such a usage cases:
2nd option
By looking at proposed solutions (in related thread), which I like, I'm just thinking what would be the advantage of this since everything is sent to client in json most times. But still, it there will be cases when no json is used (but xml?), or we just want to handle the parsing by ourselves, maybe it is enough to just expose
complex
type parsing like it is done fordate
, so:The disadvantage is that there is only one
parseComplex
method to override, so each custom case related to eventual multiple complex types should be somehow distinguished there. But still such cases are rather rare.3rd option
The idea with dynamic typeHelpers is also attractive (taken from related thread):
4th option
We can add it all.
5th option
This is rather not an option, but we can also change nothing - by choosing that way though developers are going to handle such stuff by themselves, in a way shown by my answers at the beginning of related thread.