Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /we have to change the order in Render method or we miss if he have placeholders in the _Layout
- public string Render()
- {
- var fullHtml = this.ReadFile();
- var layoutWithView = this.AddViewToLayout(fullHtml);
- var renderedHtml = this.RenderHtml(layoutWithView);
- return renderedHtml;
- }
- //because of this :
- private object ProcessesBindingModelParameter(
- ParameterInfo actionParameter,
- IHttpRequest request)
- {
- var bindingModelType = actionParameter.ParameterType;
- var bindingModelInstance = Activator.CreateInstance(bindingModelType);
- var bindingModelProperties = bindingModelType.GetProperties();
- foreach (var bindingModelProperty in bindingModelProperties)
- {
- try
- {
- //this .ToLower create problems if you try to match confirmPassword with confirmPassword in viewModel
- //confirmpassword != confirmPassword and we get the Exception
- //it is fixed easily maybe have other posibilities but this was the fastest I found and did work
- // Also calculated properties cause the exception too but are working fine just because they cant bi bind on
- // runtime before we actually need them in our code it cause the exception message
- var value = this.GetParameterFromRequestData(
- request,
- bindingModelProperty.Name.ToLower());
- bindingModelProperty.SetValue(
- bindingModelInstance,
- Convert.ChangeType(value, bindingModelProperty.PropertyType));
- }
- catch (Exception)
- {
- Console.WriteLine($"The property {bindingModelProperty.Name} could not be mapped");
- }
- }
- return Convert.ChangeType(bindingModelInstance, bindingModelType);
- }
- // we have to make small changes to HttpRequest
- private void ParseQueryParameters()
- {
- if (!this.Url.Contains('?'))
- {
- return;
- }
- string queryString = this.Url
- .Split(new[] { '?', '#' }, StringSplitOptions.None)[1];
- if (string.IsNullOrWhiteSpace(queryString))
- {
- return;
- }
- string[] queryParameters = queryString.Split('&');
- if (!this.IsValidRequestQueryString(queryString, queryParameters))
- {
- throw new BadRequestException();
- }
- foreach (var queryParameter in queryParameters)
- {
- string[] parameterArguments = queryParameter
- .Split('=', StringSplitOptions.RemoveEmptyEntries);
- this.QueryData.Add(parameterArguments[0].ToLower(), parameterArguments[1]);
- }
- }
- private void ParseFormDataParameters(string formData)
- {
- if (string.IsNullOrEmpty(formData))
- {
- return;
- }
- string[] formDataParams = formData.Split(HttpRequestParameterSeparator);
- foreach (var formDataParameter in formDataParams)
- {
- string[] parameterArguments = formDataParameter
- .Split(HttpRequestParameterNameValueSeparator, StringSplitOptions.RemoveEmptyEntries);
- this.FormData.Add(parameterArguments[0].ToLower(), parameterArguments[1]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment