Skip to content

Commit

Permalink
AspNetResponseCookieLayoutRenderer - Reduce code complexity (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored Dec 14, 2022
1 parent fb9c5a4 commit 6a2c203
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/Shared/LayoutRenderers/AspNetResponseCookieLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ private void SerializeAllPropertiesJson(IEnumerable<HttpCookie> verboseCookieVal

builder.Append('{');

includeSeparator = AppendJsonProperty(builder, nameof(cookie.Name), cookie.Name, false);
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Value), cookie.Value, includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Domain), cookie.Domain, includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Path), cookie.Path, includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Expires), cookie.Expires.ToUniversalTime().ToString("u"), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), includeSeparator) || includeSeparator;
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Name), cookie.Name, false);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Value), cookie.Value, includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Domain), cookie.Domain, includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Path), cookie.Path, includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Expires), cookie.Expires.ToUniversalTime().ToString("u"), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), includeSeparator);

builder.Append('}');

Expand Down Expand Up @@ -247,13 +247,13 @@ private void SerializeAllPropertiesFlat(IEnumerable<HttpCookie> verboseCookieVal
}
firstObject = false;

includeSeparator = AppendFlatProperty(builder, nameof(cookie.Name), cookie.Name, valueSeparator, "");
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Value), cookie.Value, valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Domain), cookie.Domain, valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Path), cookie.Path, valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Expires), cookie.Expires.ToUniversalTime().ToString("u"), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Name), cookie.Name, valueSeparator, "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Value), cookie.Value, valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Domain), cookie.Domain, valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Path), cookie.Path, valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Expires), cookie.Expires.ToUniversalTime().ToString("u"), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
}
}

Expand Down Expand Up @@ -395,14 +395,14 @@ private void SerializeAllPropertiesJson(IEnumerable<SetCookieHeaderValue> verbos

builder.Append('{');

includeSeparator = AppendJsonProperty(builder, nameof(cookie.Name), cookie.Name.ToString(), false);
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Value), cookie.Value.ToString(), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Domain), cookie.Domain.ToString(), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Path), cookie.Path.ToString(), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Expires), cookie.Expires?.ToUniversalTime().ToString("u"), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), includeSeparator) || includeSeparator;
includeSeparator = AppendJsonProperty(builder, nameof(cookie.SameSite), cookie.SameSite.ToString(), includeSeparator) || includeSeparator;
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Name), cookie.Name.ToString(), false);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Value), cookie.Value.ToString(), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Domain), cookie.Domain.ToString(), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Path), cookie.Path.ToString(), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Expires), cookie.Expires?.ToUniversalTime().ToString("u"), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), includeSeparator);
includeSeparator |= AppendJsonProperty(builder, nameof(cookie.SameSite), cookie.SameSite.ToString(), includeSeparator);

builder.Append('}');

Expand Down Expand Up @@ -438,14 +438,14 @@ private void SerializeAllPropertiesFlat(IEnumerable<SetCookieHeaderValue> verbos
}
firstObject = false;

includeSeparator = AppendFlatProperty(builder, nameof(cookie.Name), cookie.Name.ToString(), valueSeparator, "");
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Value), cookie.Value.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Domain), cookie.Domain.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Path), cookie.Path.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Expires), cookie.Expires?.ToUniversalTime().ToString("u"), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator = AppendFlatProperty(builder, nameof(cookie.SameSite), cookie.SameSite.ToString(), valueSeparator, includeSeparator ? propertySeparator : "") || includeSeparator;
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Name), cookie.Name.ToString(), valueSeparator, "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Value), cookie.Value.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Domain), cookie.Domain.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Path), cookie.Path.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Expires), cookie.Expires?.ToUniversalTime().ToString("u"), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.Secure), cookie.Secure.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.HttpOnly), cookie.HttpOnly.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
includeSeparator |= AppendFlatProperty(builder, nameof(cookie.SameSite), cookie.SameSite.ToString(), valueSeparator, includeSeparator ? propertySeparator : "");
}
}
#endif
Expand Down

0 comments on commit 6a2c203

Please sign in to comment.