Skip to content

Commit b4f1c3d

Browse files
authored
Merge pull request #664 from dmilov/bug/fix-for-663-remove-constructor-sideeffect
Fixes #663. Remove 'Configuration' constructor sideeffect
2 parents 4a1bc8f + 983536a commit b4f1c3d

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/main/resources/handlebars/csharp/Configuration.mustache

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ namespace {{packageName}}.Client
113113
ApiKey = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
114114
ApiKeyPrefix = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
115115

116-
// Setting Timeout has side effects (forces ApiClient creation).
117116
Timeout = 100000;
118117
}
119118

@@ -236,15 +235,49 @@ namespace {{packageName}}.Client
236235
/// </summary>
237236
public virtual IDictionary<string, string> DefaultHeader { get; set; }
238237
238+
private int _timeout = 100000;
239239
/// <summary>
240240
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
241241
/// </summary>
242242
public virtual int Timeout
243243
{
244-
{{#netStandard}}get { return (int)ApiClient.RestClient.Timeout.GetValueOrDefault(TimeSpan.FromSeconds(0)).TotalMilliseconds; }
245-
set { ApiClient.RestClient.Timeout = TimeSpan.FromMilliseconds(value); }{{/netStandard}}{{^netStandard}}
246-
get { return ApiClient.RestClient.Timeout; }
247-
set { ApiClient.RestClient.Timeout = value; }{{/netStandard}}
244+
{{#netStandard}}get
245+
{
246+
if (_apiClient == null)
247+
{
248+
return _timeout;
249+
} else
250+
{
251+
return (int)ApiClient.RestClient.Timeout.GetValueOrDefault(TimeSpan.FromSeconds(0)).TotalMilliseconds;
252+
}
253+
}
254+
set
255+
{
256+
_timeout = value;
257+
if (_apiClient != null)
258+
{
259+
ApiClient.RestClient.Timeout = TimeSpan.FromMilliseconds(_timeout);
260+
}
261+
}{{/netStandard}}{{^netStandard}}
262+
get
263+
{
264+
if (_apiClient == null)
265+
{
266+
return _timeout;
267+
}
268+
else
269+
{
270+
return ApiClient.RestClient.Timeout;
271+
}
272+
}
273+
set
274+
{
275+
_timeout = value;
276+
if (_apiClient != null)
277+
{
278+
ApiClient.RestClient.Timeout = _timeout;
279+
}
280+
}{{/netStandard}}
248281
}
249282
250283
/// <summary>

0 commit comments

Comments
 (0)