isharpsolutions/Missing — Issue #1: Strongly typed handling of forms/querystring
Author: pingvinen
Created: 2012-03-07 23:18:01+00:00
State: open
Labels: enhancement

It would be awesome to replace our old Collections.NameValueCollection.GetString(...) stuff with some sort of strongly typed data carrier.

Consider a form like this

<form>
<input type="text" name="FirstName"/>
<input type="text" name="LastName" />
<input type="text" name="Age" />
</form>

...and in the backend...

public void Handler(HttpContext context)
{
RequestInput input = new RequestInput(context.Request.Form,
new Input("FirstName", typeof(String), String.Empty),
new Input("LastName", typeof(String), String.Empty),
new Input("Age", typeof(int), -1)
);

if (input.FirstName.Equals(String.Empty))
{
throw new Exception("FirstName not set");
}

...
}

It can probably be made with a much nicer syntax, but the gist is that the consumer can define the inputs he expects with "name", "type" and "default value".

We could try to find out how WebMatrix.Data does this.