Skip to content

Commit

Permalink
Action code change suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
canton7 committed Nov 5, 2022
1 parent f80748c commit 0cc2dbf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 36 deletions.
4 changes: 1 addition & 3 deletions src/Common/Implementation/ImplementationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@ IEnumerable<string> GetMissingParams(string path)

private void ValidatePathParams(MethodModel method, AttributeModel<RequestAttributeBase> requestAttribute)
{
string? path = requestAttribute.Attribute.Path;
if (path == null)
path = string.Empty;
string? path = requestAttribute.Attribute.Path ?? string.Empty;

var pathParams = method.Parameters.Where(x => x.PathAttribute != null).ToList();

Expand Down
39 changes: 13 additions & 26 deletions src/RestEase/Implementation/RequestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ public RequestInfo(HttpMethod method, string path, MethodInfo methodInfo)
/// <param name="format">Format string to use</param>
public void AddQueryParameter<T>(QuerySerializationMethod serializationMethod, string name, T value, string? format = null)
{
if (this._queryParams == null)
this._queryParams = new List<QueryParameterInfo>();
this._queryParams ??= new List<QueryParameterInfo>();

this._queryParams.Add(new QueryParameterInfo<T>(serializationMethod, name, value, format));
}
Expand All @@ -173,8 +172,7 @@ public void AddQueryParameter<T>(QuerySerializationMethod serializationMethod, s
/// <param name="format">Format string to use</param>
public void AddQueryCollectionParameter<T>(QuerySerializationMethod serializationMethod, string name, IEnumerable<T> values, string? format = null)
{
if (this._queryParams == null)
this._queryParams = new List<QueryParameterInfo>();
this._queryParams ??= new List<QueryParameterInfo>();

this._queryParams.Add(new QueryCollectionParameterInfo<T>(serializationMethod, name, values, format));
}
Expand All @@ -191,8 +189,7 @@ public void AddQueryMap<TKey, TValue>(QuerySerializationMethod serializationMeth
if (queryMap == null)
return;

if (this._queryParams == null)
this._queryParams = new List<QueryParameterInfo>();
this._queryParams ??= new List<QueryParameterInfo>();

foreach (var kvp in queryMap)
{
Expand Down Expand Up @@ -228,8 +225,7 @@ public void AddQueryCollectionMap<TKey, TValue, TElement>(QuerySerializationMeth
if (queryMap == null)
return;

if (this._queryParams == null)
this._queryParams = new List<QueryParameterInfo>();
this._queryParams ??= new List<QueryParameterInfo>();

foreach (var kvp in queryMap)
{
Expand All @@ -245,8 +241,7 @@ public void AddQueryCollectionMap<TKey, TValue, TElement>(QuerySerializationMeth
/// <param name="value">Raw query parameter</param>
public void AddRawQueryParameter<T>(T value)
{
if (this._rawQueryParameterInfos == null)
this._rawQueryParameterInfos = new List<RawQueryParameterInfo>();
this._rawQueryParameterInfos ??= new List<RawQueryParameterInfo>();

this._rawQueryParameterInfos.Add(new RawQueryParameterInfo<T>(value));
}
Expand All @@ -262,8 +257,7 @@ public void AddRawQueryParameter<T>(T value)
/// <param name="urlEncode">Whether or not this path parameter should be URL-encoded</param>
public void AddPathParameter<T>(PathSerializationMethod serializationMethod, string name, T value, string? format = null, bool urlEncode = true)
{
if (this._pathParams == null)
this._pathParams = new List<PathParameterInfo>();
this._pathParams ??= new List<PathParameterInfo>();

this._pathParams.Add(new PathParameterInfo<T>(name, value, format, urlEncode, serializationMethod));
}
Expand All @@ -275,8 +269,7 @@ public void AddPathParameter<T>(PathSerializationMethod serializationMethod, str
/// <param name="value">Value of the key/value pair</param>
public void AddHttpRequestMessagePropertyParameter(string key, object value)
{
if (this._httpRequestMessageProperties == null)
this._httpRequestMessageProperties = new List<HttpRequestMessagePropertyInfo>();
this._httpRequestMessageProperties ??= new List<HttpRequestMessagePropertyInfo>();

this._httpRequestMessageProperties.Add(new HttpRequestMessagePropertyInfo(key, value));
}
Expand All @@ -292,8 +285,7 @@ public void AddHttpRequestMessagePropertyParameter(string key, object value)
/// <param name="urlEncode">Whether or not this path parameter should be URL-encoded</param>
public void AddPathProperty<T>(PathSerializationMethod serializationMethod, string name, T value, string? format = null, bool urlEncode = true)
{
if (this._pathProperties == null)
this._pathProperties = new List<PathParameterInfo>();
this._pathProperties ??= new List<PathParameterInfo>();

this._pathProperties.Add(new PathParameterInfo<T>(name, value, format, urlEncode, serializationMethod));
}
Expand All @@ -308,8 +300,7 @@ public void AddPathProperty<T>(PathSerializationMethod serializationMethod, stri
/// <param name="format">Format string to use</param>
public void AddQueryProperty<T>(QuerySerializationMethod serializationMethod, string name, T value, string? format = null)
{
if (this._queryProperties == null)
this._queryProperties = new List<QueryParameterInfo>();
this._queryProperties ??= new List<QueryParameterInfo>();

this._queryProperties.Add(new QueryParameterInfo<T>(serializationMethod, name, value, format));
}
Expand All @@ -321,8 +312,7 @@ public void AddQueryProperty<T>(QuerySerializationMethod serializationMethod, st
/// <param name="value">Value of the key/value pair</param>
public void AddHttpRequestMessagePropertyProperty(string key, object value)
{
if (this._httpRequestMessageProperties == null)
this._httpRequestMessageProperties = new List<HttpRequestMessagePropertyInfo>();
this._httpRequestMessageProperties ??= new List<HttpRequestMessagePropertyInfo>();

this._httpRequestMessageProperties.Add(new HttpRequestMessagePropertyInfo(key, value));
}
Expand All @@ -337,8 +327,7 @@ public void AddHttpRequestMessagePropertyProperty(string key, object value)
/// <param name="format">Format string to use</param>
public void AddPropertyHeader<T>(string name, T value, string? defaultValue, string? format = null)
{
if (this._propertyHeaders == null)
this._propertyHeaders = new List<HeaderParameterInfo>();
this._propertyHeaders ??= new List<HeaderParameterInfo>();

this._propertyHeaders.Add(new HeaderParameterInfo<T>(name, value, defaultValue, format));
}
Expand All @@ -350,8 +339,7 @@ public void AddPropertyHeader<T>(string name, T value, string? defaultValue, str
/// <param name="value">Value of the header to add</param>
public void AddMethodHeader(string name, string value)
{
if (this._methodHeaders == null)
this._methodHeaders = new List<KeyValuePair<string, string?>>();
this._methodHeaders ??= new List<KeyValuePair<string, string?>>();

this._methodHeaders.Add(new KeyValuePair<string, string?>(name, value));
}
Expand All @@ -365,8 +353,7 @@ public void AddMethodHeader(string name, string value)
/// <param name="format">Format string to use</param>
public void AddHeaderParameter<T>(string name, T value, string? format = null)
{
if (this._headerParams == null)
this._headerParams = new List<HeaderParameterInfo>();
this._headerParams ??= new List<HeaderParameterInfo>();

this._headerParams.Add(new HeaderParameterInfo<T>(name, value, null, format));
}
Expand Down
5 changes: 1 addition & 4 deletions src/RestEase/Implementation/Requester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,7 @@ protected virtual void ApplyHeadersSet(
{
// If they've added a content header, my reading of the RFC is that we are actually sending a body (even if they haven't
// said what should be in it), and therefore we need to send Content-Length
if (dummyContent == null)
{
dummyContent = new ByteArrayContent(ArrayUtil.Empty<byte>());
}
dummyContent ??= new ByteArrayContent(ArrayUtil.Empty<byte>());

added = dummyContent.Headers.TryAddWithoutValidation(headersGroup.Key, headersToAdd);
if (added && (areMethodHeaders || requestInfo.BodyParameterInfo != null))
Expand Down
2 changes: 1 addition & 1 deletion src/RestEase/RequestBodySerializerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RestEase
/// <remarks>
/// This is broken out as a separate structure so that extra properties can be added without breaking backwards compatibility
/// </remarks>
public struct RequestBodySerializerInfo
public readonly struct RequestBodySerializerInfo
{
/// <summary>
/// Gets information about the request
Expand Down
2 changes: 1 addition & 1 deletion src/RestEase/RequestPathParamSerializerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RestEase
/// <remarks>
/// This is broken out as a separate structure so that extra properties can be added without breaking backwards compatibility
/// </remarks>
public struct RequestPathParamSerializerInfo
public readonly struct RequestPathParamSerializerInfo
{
/// <summary>
/// Gets information about the request
Expand Down
2 changes: 1 addition & 1 deletion src/RestEase/ResponseDeserializerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// <remarks>
/// This is broken out as a separate structure so that extra properties can be added without breaking backwards compatibility
/// </remarks>
public struct ResponseDeserializerInfo
public readonly struct ResponseDeserializerInfo
{
/// <summary>
/// Gets information about the request
Expand Down

0 comments on commit 0cc2dbf

Please sign in to comment.