Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Binding logic is extremely inefficient #243

Open
davidfowl opened this issue Mar 14, 2020 · 3 comments
Open

Form Binding logic is extremely inefficient #243

davidfowl opened this issue Mar 14, 2020 · 3 comments

Comments

@davidfowl
Copy link

@davidfowl davidfowl commented Mar 14, 2020

Bytes -> Dictionary -> Another Dictionary -> JSON string -> Object

if (request.HasFormContentType)
{
var res = request.Form.ToDictionary(key => key.Key, val =>
{
var type = typeof(T);
var propertyType = type.GetProperty(val.Key)?.PropertyType;
if (propertyType == null)
{
return null;
}
if (propertyType.IsArray() || propertyType.IsCollection() || propertyType.IsEnumerable())
{
var colType = propertyType.GetElementType();
if (colType == null)
{
colType = propertyType.GetGenericArguments().First();
}
return val.Value.Select(y => { return ConvertToType(y, colType); });
}
return ConvertToType(val.Value[0], propertyType);
});
var json = JsonSerializer.Serialize(res);
return JsonSerializer.Deserialize<T>(json);
}

@jchannon
Copy link
Member

@jchannon jchannon commented Mar 15, 2020

@davidfowl
Copy link
Author

@davidfowl davidfowl commented Mar 15, 2020

It would be good to understand if people are using this feature of Carter. Especially if it’s mostly used for backend APIs maybe you can eventually kill the feature

@jchannon
Copy link
Member

@jchannon jchannon commented Mar 15, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.