mirror of
https://github.com/jellyfin/jellyfin-sdk-csharp.git
synced 2024-11-23 05:39:51 +00:00
update nswag
This commit is contained in:
parent
64a21440ed
commit
7fc0e928dc
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Nullable>enable</Nullable>
|
||||
@ -12,13 +12,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
|
||||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
|
||||
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
@ -21,34 +21,26 @@
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<Description>Auto generated sdk for Jellyfin.</Description>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0'">
|
||||
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PackageReference Include="NSwag.MSBuild" Version="14.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NSwag.MSBuild" Version="13.18.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Text.Json" Version="7.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
<!-- Code Analyzers-->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
|
||||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<Target Name="GenerateSdk">
|
||||
<Exec Command="$(NSwagExe_Net70) run nswag.json" />
|
||||
<Exec Command="$(NSwagExe_Net80) run nswag.json" />
|
||||
</Target>
|
||||
<Target Name="GenerateSdk-Unstable">
|
||||
<Exec Command="$(NSwagExe_Net70) run nswag.unstable.json" />
|
||||
<Exec Command="$(NSwagExe_Net80) run nswag.unstable.json" />
|
||||
</Target>
|
||||
</Project>
|
37308
src/JellyfinSdk.g.cs
37308
src/JellyfinSdk.g.cs
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
{
|
||||
"runtime": "Net70",
|
||||
"runtime": "Net80",
|
||||
"defaultVariables": null,
|
||||
"documentGenerator": {
|
||||
"fromDocument": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"runtime": "Net70",
|
||||
"runtime": "Net80",
|
||||
"defaultVariables": null,
|
||||
"documentGenerator": {
|
||||
"fromDocument": {
|
||||
|
@ -37,10 +37,19 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu
|
||||
{
|
||||
return System.Convert.ToBase64String((byte[]) value);
|
||||
}
|
||||
else if (value is string[])
|
||||
{
|
||||
return string.Join(",", (string[])value);
|
||||
}
|
||||
else if (value.GetType().IsArray)
|
||||
{
|
||||
var array = System.Linq.Enumerable.OfType<object>((System.Array) value);
|
||||
return string.Join(",", System.Linq.Enumerable.Select(array, o => ConvertToString(o, cultureInfo)));
|
||||
var valueArray = (System.Array)value;
|
||||
var valueTextArray = new string[valueArray.Length];
|
||||
for (var i = 0; i < valueArray.Length; i++)
|
||||
{
|
||||
valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo);
|
||||
}
|
||||
return string.Join(",", valueTextArray);
|
||||
}
|
||||
|
||||
var result = System.Convert.ToString(value, cultureInfo);
|
||||
|
@ -1,13 +1,25 @@
|
||||
{% if parameter.IsDateTimeArray -%}
|
||||
urlBuilder_.Replace("{{ "{" }}{{ parameter.Name }}}", System.Uri.EscapeDataString(string.Join(",", System.Linq.Enumerable.Select({{ parameter.VariableName }}, s_ => s_.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture)))));
|
||||
for (var i = 0; i < {{ parameter.VariableName }}.Length; i++)
|
||||
{
|
||||
if (i > 0) urlBuilder_.Append(',');
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString({{ parameter.VariableName }}[i].ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture)));
|
||||
}
|
||||
{% elsif parameter.IsDateArray -%}
|
||||
urlBuilder_.Replace("{{ "{" }}{{ parameter.Name }}}", System.Uri.EscapeDataString(string.Join(",", System.Linq.Enumerable.Select({{ parameter.VariableName }}, s_ => s_.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture)))));
|
||||
for (var i = 0; i < {{ parameter.VariableName }}.Length; i++)
|
||||
{
|
||||
if (i > 0) urlBuilder_.Append(',');
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString({{ parameter.VariableName }}[i].ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture)));
|
||||
}
|
||||
{% elsif parameter.IsDateTime -%}
|
||||
urlBuilder_.Replace("{{ "{" }}{{ parameter.Name }}}", System.Uri.EscapeDataString({{ parameter.VariableName }}.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture)));
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString({{ parameter.VariableName }}.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture)));
|
||||
{% elsif parameter.IsDate -%}
|
||||
urlBuilder_.Replace("{{ "{" }}{{ parameter.Name }}}", System.Uri.EscapeDataString({{ parameter.VariableName }}.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture)));
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString({{ parameter.VariableName }}.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture)));
|
||||
{% elsif parameter.IsArray -%}
|
||||
urlBuilder_.Replace("{{ "{" }}{{ parameter.Name }}}", System.Uri.EscapeDataString(string.Join(",", System.Linq.Enumerable.Select({{ parameter.VariableName }}, s_ => ConvertToString(s_, System.Globalization.CultureInfo.InvariantCulture)))));
|
||||
for (var i = 0; i < {{ parameter.VariableName }}.Length; i++)
|
||||
{
|
||||
if (i > 0) urlBuilder_.Append(',');
|
||||
urlBuilder_.Append(ConvertToString({{ parameter.VariableName }}[i], System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
{% else -%}
|
||||
urlBuilder_.Replace("{{ "{" }}{{ parameter.Name }}}", System.Uri.EscapeDataString(ConvertToString({{ parameter.VariableName }}, System.Globalization.CultureInfo.InvariantCulture)));
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString({{ parameter.VariableName }}, System.Globalization.CultureInfo.InvariantCulture)));
|
||||
{%- endif %}
|
||||
|
@ -1,44 +1,44 @@
|
||||
{% if parameter.IsDateTimeArray -%}
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString(item_.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture))).Append("&"); }
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}")).Append('=').Append(System.Uri.EscapeDataString(item_.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); }
|
||||
{% elsif parameter.IsDateArray -%}
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString(item_.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture))).Append("&"); }
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}")).Append('=').Append(System.Uri.EscapeDataString(item_.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); }
|
||||
{% elsif parameter.IsDateTime -%}
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}{{ parameter.VariableName }}{% if parameter.IsSystemNullable %}.Value{% endif %}.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append("&");
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}")).Append('=').Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}{{ parameter.VariableName }}{% if parameter.IsSystemNullable %}.Value{% endif %}.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append('&');
|
||||
{% elsif parameter.IsDate -%}
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}{{ parameter.VariableName }}{% if parameter.IsSystemNullable %}.Value{% endif %}.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append("&");
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}")).Append('=').Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}{{ parameter.VariableName }}{% if parameter.IsSystemNullable %}.Value{% endif %}.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append('&');
|
||||
{% elsif parameter.IsArray -%}
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); }
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); }
|
||||
{% elsif parameter.IsDictionary -%}
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString(item_.Key) + "=").Append(System.Uri.EscapeDataString(ConvertToString(item_.Value, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); }
|
||||
foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.Uri.EscapeDataString(item_.Key)).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(item_.Value, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); }
|
||||
{% elsif parameter.IsDeepObject -%}
|
||||
{% for property in parameter.PropertyNames -%}
|
||||
if ({{parameter.Name}}.{{property.Name}} != null)
|
||||
{
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{parameter.Name}}[{{property.Key}}]") + "=").Append(System.Uri.EscapeDataString(ConvertToString({{parameter.Name}}.{{property.Name}}, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{parameter.Name}}[{{property.Key}}]")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString({{parameter.Name}}.{{property.Name}}, System.Globalization.CultureInfo.InvariantCulture))).Append('&');
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for property in parameter.CollectionPropertyNames -%}
|
||||
if ({{parameter.Name}}.{{property.Name}} != null && {{parameter.Name}}.{{property.Name}}.Count > 0)
|
||||
{
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{parameter.Name}}[{{property.Key}}]") + "=");
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{parameter.Name}}[{{property.Key}}]")).Append('=');
|
||||
foreach (var p_ in {{parameter.Name}}.{{property.Name}})
|
||||
{
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(p_, System.Globalization.CultureInfo.InvariantCulture))).Append(",");
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(p_, System.Globalization.CultureInfo.InvariantCulture))).Append(',');
|
||||
}
|
||||
urlBuilder_.Length--;
|
||||
urlBuilder_.Append("&");
|
||||
urlBuilder_.Append('&');
|
||||
}
|
||||
{% endfor -%}
|
||||
{% elsif parameter.Explode and parameter.IsForm and parameter.IsObject -%}
|
||||
{% for property in parameter.PropertyNames -%}
|
||||
if ({{parameter.Name}}.{{property.Name}} != null)
|
||||
{
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{property.Key}}") + "=").Append(System.Uri.EscapeDataString(ConvertToString({{parameter.Name}}.{{property.Name}}, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{property.Key}}")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString({{parameter.Name}}.{{property.Name}}, System.Globalization.CultureInfo.InvariantCulture))).Append('&');
|
||||
}
|
||||
{% endfor -%}
|
||||
{% elsif parameter.HasAdditionalProperties == false -%}
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}ConvertToString({{ parameter.VariableName }}, System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append("&");
|
||||
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}")).Append('=').Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}ConvertToString({{ parameter.VariableName }}, System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append('&');
|
||||
{% endif -%}
|
||||
{% if parameter.HasAdditionalProperties -%}
|
||||
foreach (var item_ in {{parameter.Name}}.AdditionalProperties) { urlBuilder_.Append(System.Uri.EscapeDataString(item_.Key) + "=").Append(System.Uri.EscapeDataString(ConvertToString(item_.Value, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); }
|
||||
foreach (var item_ in {{parameter.Name}}.AdditionalProperties) { urlBuilder_.Append(System.Uri.EscapeDataString(item_.Key)).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(item_.Value, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); }
|
||||
{% endif -%}
|
||||
|
@ -2,50 +2,71 @@
|
||||
[System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
|
||||
{{ ClientClassAccessModifier }} partial class {{ Class }} {% if HasBaseType %}: {% endif %}{% if HasBaseClass %}{{ BaseClass }}{% if GenerateClientInterfaces %}, {% endif %}{% endif %}{% if GenerateClientInterfaces %}I{{ Class }}{% endif %}
|
||||
{
|
||||
{% if UseBaseUrl and GenerateBaseUrlProperty -%}
|
||||
private string _baseUrl = "{{ BaseUrl }}";
|
||||
{% if UseBaseUrl or GenerateBaseUrlProperty -%}
|
||||
#pragma warning disable 8618
|
||||
private string _baseUrl;
|
||||
#pragma warning restore 8618
|
||||
|
||||
{% endif -%}
|
||||
{% if InjectHttpClient -%}
|
||||
private {{ HttpClientType }} _httpClient;
|
||||
{% endif -%}
|
||||
{% if UseRequestAndResponseSerializationSettings -%}
|
||||
private System.Lazy<{{ JsonSerializerSettingsType }}> _requestSettings;
|
||||
private System.Lazy<{{ JsonSerializerSettingsType }}> _responseSettings;
|
||||
private static System.Lazy<{{ JsonSerializerSettingsType }}> _requestSettings = new System.Lazy<{{ JsonSerializerSettingsType }}>(() => CreateSerializerSettings(true), true);
|
||||
private static System.Lazy<{{ JsonSerializerSettingsType }}> _responseSettings = new System.Lazy<{{ JsonSerializerSettingsType }}>(() => CreateSerializerSettings(false), true);
|
||||
{% else -%}
|
||||
private System.Lazy<{{ JsonSerializerSettingsType }}> _settings;
|
||||
private static System.Lazy<{{ JsonSerializerSettingsType }}> _settings = new System.Lazy<{{ JsonSerializerSettingsType }}>(CreateSerializerSettings, true);
|
||||
{% endif -%}
|
||||
|
||||
{% assign constructorParameters = "" -%}
|
||||
{% if HasConfigurationClass -%}
|
||||
public {{ Class }}({{ ConfigurationClass }} configuration{% if InjectHttpClient %}, {{ HttpClientType }} httpClient{% endif %}) : base(configuration)
|
||||
{
|
||||
{% if InjectHttpClient -%}
|
||||
_httpClient = httpClient;
|
||||
{% endif -%}
|
||||
{% elsif UseBaseUrl and HasBaseUrl == false %}
|
||||
public {{ Class }}(string baseUrl{% if InjectHttpClient %}, {{ HttpClientType }} httpClient{% endif %})
|
||||
{% assign constructorParameters = ConfigurationClass | append: " configuration" -%}
|
||||
{% endif -%}
|
||||
{% if UseBaseUrl and HasBaseUrl == false and HasConfigurationClass == false -%}
|
||||
{% unless constructorParameters == "" -%}{% assign constructorParameters = constructorParameters | append: ", " -%}{% endunless -%}
|
||||
{% assign constructorParameters = constructorParameters | append: "string baseUrl" -%}
|
||||
{% endif -%}
|
||||
{% if InjectHttpClient -%}
|
||||
{% unless constructorParameters == "" -%}{% assign constructorParameters = constructorParameters | append: ", " -%}{% endunless -%}
|
||||
{% assign constructorParameters = constructorParameters | append: HttpClientType | append: " httpClient" -%}
|
||||
{% endif -%}
|
||||
public {{ Class }}({{ constructorParameters }}){% if HasConfigurationClass and HasBaseClass -%}{{ " : base(configuration)"}}{% endif %}
|
||||
{
|
||||
{% if UseBaseUrl -%}
|
||||
{% if HasBaseUrl -%}
|
||||
{% if GenerateBaseUrlProperty -%}
|
||||
BaseUrl = "{{ BaseUrl }}";
|
||||
{% else -%}
|
||||
{% if BaseUrl != "" -%}
|
||||
{% assign baseUrlLength = BaseUrl | size -%}
|
||||
{% assign lastUrlCharIndex = baseUrlLength | minus: 1 -%}
|
||||
{% assign lastUrlChar = BaseUrl | slice: lastUrlCharIndex, 1 -%}
|
||||
{% if lastUrlChar == "/" -%}
|
||||
_baseUrl = "{{ BaseUrl }}";
|
||||
{% else -%}
|
||||
_baseUrl = "{{ BaseUrl }}/";
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% else -%}
|
||||
{% if GenerateBaseUrlProperty -%}
|
||||
BaseUrl = baseUrl;
|
||||
{% else -%}
|
||||
{% if HasConfigurationClass == false -%}
|
||||
_baseUrl = (string.IsNullOrEmpty(baseUrl) || baseUrl.EndsWith("/"))
|
||||
? baseUrl
|
||||
: baseUrl + "/";
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% if InjectHttpClient -%}
|
||||
_httpClient = httpClient;
|
||||
{% endif -%}
|
||||
{% elsif InjectHttpClient %}
|
||||
public {{ Class }}({{ HttpClientType }} httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
{% else -%}
|
||||
public {{ Class }}()
|
||||
{
|
||||
{% endif -%}
|
||||
{% if UseRequestAndResponseSerializationSettings -%}
|
||||
_requestSettings = new System.Lazy<{{ JsonSerializerSettingsType }}>(() => CreateSerializerSettings(true));
|
||||
_responseSettings = new System.Lazy<{{ JsonSerializerSettingsType }}>(() => CreateSerializerSettings(false));
|
||||
{% else -%}
|
||||
_settings = new System.Lazy<{{ JsonSerializerSettingsType }}>(CreateSerializerSettings);
|
||||
{% endif -%}
|
||||
{% template Client.Class.Constructor %}
|
||||
{% template Client.Class.Constructor %}
|
||||
}
|
||||
|
||||
private {{ JsonSerializerSettingsType }} CreateSerializerSettings({% if UseRequestAndResponseSerializationSettings %}bool isRequest{% endif %})
|
||||
private static {{ JsonSerializerSettingsType }} CreateSerializerSettings({% if UseRequestAndResponseSerializationSettings %}bool isRequest{% endif %})
|
||||
{
|
||||
var settings = {{ JsonSerializerParameterCode }};
|
||||
{% if UseSystemTextJson == false and SerializeTypeInformation -%}
|
||||
@ -64,7 +85,13 @@
|
||||
public string BaseUrl
|
||||
{
|
||||
get { return _baseUrl; }
|
||||
set { _baseUrl = value; }
|
||||
[System.Diagnostics.CodeAnalysis.MemberNotNull(nameof(_baseUrl))]
|
||||
set
|
||||
{
|
||||
_baseUrl = value;
|
||||
if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/"))
|
||||
_baseUrl += '/';
|
||||
}
|
||||
}
|
||||
|
||||
{% endif -%}
|
||||
@ -82,9 +109,9 @@
|
||||
|
||||
{% if GenerateUpdateJsonSerializerSettingsMethod -%}
|
||||
{% if UseRequestAndResponseSerializationSettings -%}
|
||||
partial void UpdateJsonSerializerSettings({{ JsonSerializerSettingsType }} settings, bool isRequest);
|
||||
static partial void UpdateJsonSerializerSettings({{ JsonSerializerSettingsType }} settings, bool isRequest);
|
||||
{% else -%}
|
||||
partial void UpdateJsonSerializerSettings({{ JsonSerializerSettingsType }} settings);
|
||||
static partial void UpdateJsonSerializerSettings({{ JsonSerializerSettingsType }} settings);
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
|
||||
@ -95,7 +122,6 @@
|
||||
partial void ProcessResponse({{ HttpClientType }} client, System.Net.Http.HttpResponseMessage response);
|
||||
{% endif -%}
|
||||
{% for operation in Operations %}
|
||||
{% assign http_method = operation.HttpMethodUpper | upcase %}
|
||||
{% if GenerateOptionalParameters == false -%}
|
||||
{% template Client.Method.Documentation %}
|
||||
{% template Client.Method.Annotations %}
|
||||
@ -114,56 +140,6 @@
|
||||
}
|
||||
|
||||
{% endif -%}
|
||||
{%- if http_method == 'GET' and operation.SyncResultType == 'FileResponse' -%}
|
||||
{% template Client.Method.Documentation %}
|
||||
{% template Client.Method.Annotations %}
|
||||
{{ operation.MethodAccessModifier }} virtual string {{ operation.ActualOperationName }}Url({% for parameter in operation.Parameters %}{{ parameter.Type }} {{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %} = null{% endif %}{% if parameter.IsLast == false %}, {% endif %}{% endfor %})
|
||||
{
|
||||
{% for parameter in operation.PathParameters -%}
|
||||
{% if parameter.IsNullable == false and parameter.IsRequired -%}
|
||||
if ({{ parameter.VariableName }} == null)
|
||||
throw new System.ArgumentNullException("{{ parameter.VariableName }}");
|
||||
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% for parameter in operation.QueryParameters -%}
|
||||
{% if parameter.IsNullable == false and parameter.IsRequired -%}
|
||||
if ({{ parameter.VariableName }} == null)
|
||||
throw new System.ArgumentNullException("{{ parameter.VariableName }}");
|
||||
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
|
||||
var urlBuilder_ = new System.Text.StringBuilder();
|
||||
urlBuilder_.Append({% if UseBaseUrl %}BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/{% else %}"{% endif %}{{ operation.Path }}{% if operation.HasQueryParameters %}?{% endif %}");
|
||||
{% for parameter in operation.PathParameters -%}
|
||||
{% if parameter.IsOptional -%}
|
||||
if ({{ parameter.VariableName }} != null)
|
||||
{% template Client.Class.PathParameter %}
|
||||
else
|
||||
urlBuilder_.Replace("/{{ "{" }}{{ parameter.Name }}}", string.Empty);
|
||||
{% else -%}
|
||||
{% template Client.Class.PathParameter %}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% for parameter in operation.QueryParameters -%}
|
||||
{% if parameter.IsOptional -%}
|
||||
if ({{ parameter.VariableName }} != null)
|
||||
{
|
||||
{% template Client.Class.QueryParameter %}
|
||||
}
|
||||
{% else -%}
|
||||
{% template Client.Class.QueryParameter %}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% if operation.HasQueryParameters -%}
|
||||
urlBuilder_.Length--;
|
||||
{% endif -%}
|
||||
|
||||
PrepareRequestUrl(urlBuilder_);
|
||||
return urlBuilder_.ToString();
|
||||
}
|
||||
{% endif -%}
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
|
||||
{% template Client.Method.Documentation %}
|
||||
{% template Client.Method.Annotations %}
|
||||
@ -188,32 +164,6 @@
|
||||
throw new System.ArgumentNullException("{{ operation.ContentParameter.VariableName }}");
|
||||
|
||||
{% endif -%}
|
||||
var urlBuilder_ = new System.Text.StringBuilder();
|
||||
urlBuilder_.Append({% if UseBaseUrl %}BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/{% else %}"{% endif %}{{ operation.Path }}{% if operation.HasQueryParameters %}?{% endif %}");
|
||||
{% for parameter in operation.PathParameters -%}
|
||||
{% if parameter.IsOptional -%}
|
||||
if ({{ parameter.VariableName }} != null)
|
||||
{% template Client.Class.PathParameter %}
|
||||
else
|
||||
urlBuilder_.Replace("/{{ "{" }}{{ parameter.Name }}}", string.Empty);
|
||||
{% else -%}
|
||||
{% template Client.Class.PathParameter %}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% for parameter in operation.QueryParameters -%}
|
||||
{% if parameter.IsOptional -%}
|
||||
if ({{ parameter.VariableName }} != null)
|
||||
{
|
||||
{% template Client.Class.QueryParameter %}
|
||||
}
|
||||
{% else -%}
|
||||
{% template Client.Class.QueryParameter %}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% if operation.HasQueryParameters -%}
|
||||
urlBuilder_.Length--;
|
||||
{% endif -%}
|
||||
|
||||
{% if InjectHttpClient -%}
|
||||
var client_ = _httpClient;
|
||||
{% elsif UseHttpClientCreationMethod -%}
|
||||
@ -257,16 +207,16 @@
|
||||
var content_ = new System.Net.Http.StringContent({{ operation.ContentParameter.VariableName }});
|
||||
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("{{ operation.Consumes }}");
|
||||
{% elsif operation.ConsumesFormUrlEncoded -%}
|
||||
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject({{ operation.ContentParameter.VariableName }}, _settings.Value);
|
||||
var dictionary_ = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, string>>(json_, _settings.Value);
|
||||
var json_ = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.SerializeToUtf8Bytes{% else %}Newtonsoft.Json.JsonConvert.SerializeObject{% endif %}({{ operation.ContentParameter.VariableName }}, _settings.Value);
|
||||
var dictionary_ = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.Deserialize{% else %}Newtonsoft.Json.JsonConvert.DeserializeObject{% endif %}<System.Collections.Generic.Dictionary<string, string>>(json_, _settings.Value);
|
||||
var content_ = new System.Net.Http.FormUrlEncodedContent(dictionary_);
|
||||
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("{{ operation.Consumes }}");
|
||||
{% elsif operation.HasPlainTextBodyParameter -%}
|
||||
var content_ = new System.Net.Http.StringContent({{ operation.ContentParameter.VariableName }});
|
||||
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("{{ operation.Consumes }}");
|
||||
{% else -%}
|
||||
var json_ = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.Serialize{% else %}Newtonsoft.Json.JsonConvert.SerializeObject{% endif %}({{ operation.ContentParameter.VariableName }}, {% if SerializeTypeInformation %}typeof({{ operation.ContentParameter.Type }}), {% endif %}{% if UseRequestAndResponseSerializationSettings %}_requestSettings{% else %}_settings{% endif %}.Value);
|
||||
var content_ = new System.Net.Http.StringContent(json_);
|
||||
var json_ = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.SerializeToUtf8Bytes{% else %}Newtonsoft.Json.JsonConvert.SerializeObject{% endif %}({{ operation.ContentParameter.VariableName }}, {% if SerializeTypeInformation %}typeof({{ operation.ContentParameter.Type }}), {% endif %}{% if UseRequestAndResponseSerializationSettings %}_requestSettings{% else %}_settings{% endif %}.Value);
|
||||
var content_ = new System.Net.Http.{% if UseSystemTextJson %}ByteArrayContent{% else %}StringContent{% endif %}(json_);
|
||||
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("{{ operation.Consumes }}");
|
||||
{% endif -%}
|
||||
request_.Content = content_;
|
||||
@ -320,8 +270,8 @@
|
||||
content_.Add(new System.Net.Http.StringContent(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture)), "{{ parameter.Name }}");
|
||||
}
|
||||
{% elsif parameter.IsObject -%}
|
||||
var json_ = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.Serialize{% else %}Newtonsoft.Json.JsonConvert.SerializeObject{% endif %}({{ parameter.VariableName }}, {% if UseRequestAndResponseSerializationSettings %}_requestSettings{% else %}_settings{% endif %}.Value);
|
||||
content_.Add(new System.Net.Http.StringContent(json_), "{{ parameter.Name }}");
|
||||
var json_ = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.SerializeToUtf8Bytes{% else %}Newtonsoft.Json.JsonConvert.SerializeObject{% endif %}({{ parameter.VariableName }}, {% if UseRequestAndResponseSerializationSettings %}_requestSettings{% else %}_settings{% endif %}.Value);
|
||||
content_.Add(new System.Net.Http.{% if UseSystemTextJson %}ByteArrayContent(json_{% else %}StringContent(json_, System.Text.Encoding.UTF8, "application/json"{% endif %}), "{{ parameter.Name }}");
|
||||
{% else -%}
|
||||
content_.Add(new System.Net.Http.StringContent(ConvertToString({{ parameter.VariableName }}, System.Globalization.CultureInfo.InvariantCulture)), "{{ parameter.Name }}");
|
||||
{% endif -%}
|
||||
@ -338,6 +288,67 @@
|
||||
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("{{ operation.Produces }}"));
|
||||
{% endif -%}
|
||||
|
||||
var urlBuilder_ = new System.Text.StringBuilder();
|
||||
{% if UseBaseUrl %}if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);{% endif %}
|
||||
// Operation Path: "{{ operation.Path }}"
|
||||
{% if operation.Path contains "{" -%}
|
||||
{% assign pathParts = operation.Path | split: "{" -%}
|
||||
{% for pathPart in pathParts -%}
|
||||
{% if pathPart contains "}" -%}
|
||||
{% assign pathParameterParts = pathPart | split: "}" -%}
|
||||
{% assign pathParameterFound = true -%}
|
||||
{% for parameter in operation.PathParameters -%}
|
||||
{% if parameter.Name == pathParameterParts[0] -%}
|
||||
{% if parameter.IsOptional -%}
|
||||
{% assign pathParameterFound = false -%}
|
||||
if ({{ parameter.VariableName }} != null)
|
||||
{
|
||||
{% template Client.Class.PathParameter %}
|
||||
}
|
||||
else
|
||||
if (urlBuilder_.Length > 0) urlBuilder_.Length--;
|
||||
{% else -%}
|
||||
{% template Client.Class.PathParameter %}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% comment -%} >>> just in case {% endcomment -%}
|
||||
{% unless pathParameterFound -%}
|
||||
urlBuilder_.Append("{{ '{' }}{{ pathParameterParts[0] }}{{ '}' }}");
|
||||
{% endunless -%}
|
||||
{% comment -%} <<< just in case {% endcomment -%}
|
||||
{% assign nonParameterPartLengh = pathParameterParts[1] | size -%}
|
||||
{% if nonParameterPartLengh == 1 -%}
|
||||
urlBuilder_.Append('{{ pathParameterParts[1] }}');
|
||||
{% elsif nonParameterPartLengh > 0 -%}
|
||||
urlBuilder_.Append("{{ pathParameterParts[1] }}");
|
||||
{% endif -%}
|
||||
{% else -%}
|
||||
{% unless pathPart == "" -%}
|
||||
urlBuilder_.Append("{{ pathPart }}");
|
||||
{% endunless -%}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% else -%}
|
||||
{% unless operation.Path == "" -%}
|
||||
urlBuilder_.Append("{{ operation.Path }}");
|
||||
{% endunless -%}
|
||||
{% endif -%}
|
||||
{% if operation.HasQueryParameters -%}
|
||||
urlBuilder_.Append('?');
|
||||
{% for parameter in operation.QueryParameters -%}
|
||||
{% if parameter.IsOptional -%}
|
||||
if ({{ parameter.VariableName }} != null)
|
||||
{
|
||||
{% template Client.Class.QueryParameter %}
|
||||
}
|
||||
{% else -%}
|
||||
{% template Client.Class.QueryParameter %}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
urlBuilder_.Length--;
|
||||
{% endif -%}
|
||||
|
||||
{% if GeneratePrepareRequestAndProcessResponseAsAsyncMethods %}
|
||||
await PrepareRequestAsync(client_, request_, urlBuilder_, cancellationToken).ConfigureAwait(false);
|
||||
{% else -%}
|
||||
@ -358,7 +369,9 @@
|
||||
var disposeResponse_ = true;
|
||||
try
|
||||
{
|
||||
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
|
||||
var headers_ = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>();
|
||||
foreach (var item_ in response_.Headers)
|
||||
headers_[item_.Key] = item_.Value;
|
||||
if (response_.Content != null && response_.Content.Headers != null)
|
||||
{
|
||||
foreach (var item_ in response_.Content.Headers)
|
||||
|
@ -4,7 +4,6 @@ public partial interface I{{ Class }}{% if HasClientBaseInterface %} : {{ Client
|
||||
{
|
||||
{% template Client.Interface.Body %}
|
||||
{% for operation in InterfaceOperations -%}
|
||||
{%- assign http_method = operation.HttpMethodUpper | upcase -%}
|
||||
{% if GenerateOptionalParameters == false -%}
|
||||
{% template Client.Method.Documentation %}
|
||||
{% template Client.Method.Annotations %}
|
||||
@ -17,12 +16,6 @@ public partial interface I{{ Class }}{% if HasClientBaseInterface %} : {{ Client
|
||||
{{ operation.SyncResultType }} {{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{{ parameter.Type }} {{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %} = null{% endif %}{% if parameter.IsLast == false %}, {% endif %}{% endfor %});
|
||||
|
||||
{%- endif %}
|
||||
{%- if http_method == 'GET' and operation.SyncResultType == 'FileResponse' -%}
|
||||
{% template Client.Method.Documentation %}
|
||||
{% template Client.Method.Annotations %}
|
||||
string {{ operation.ActualOperationName }}Url({% for parameter in operation.Parameters %}{{ parameter.Type }} {{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %} = null{% endif %}{% if parameter.IsLast == false %}, {% endif %}{% endfor %});
|
||||
|
||||
{%- endif -%}
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
|
||||
{% template Client.Method.Documentation %}
|
||||
{% template Client.Method.Annotations %}
|
||||
|
11
src/templates/File.Footer.liquid
Normal file
11
src/templates/File.Footer.liquid
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma warning restore 108
|
||||
#pragma warning restore 114
|
||||
#pragma warning restore 472
|
||||
#pragma warning restore 612
|
||||
#pragma warning restore 1573
|
||||
#pragma warning restore 1591
|
||||
#pragma warning restore 8073
|
||||
#pragma warning restore 3016
|
||||
#pragma warning restore 8603
|
||||
#pragma warning restore 8604
|
||||
#pragma warning restore 8625
|
@ -1,8 +1,11 @@
|
||||
#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended."
|
||||
#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword."
|
||||
#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?'
|
||||
#pragma warning disable 612 // Disable "CS0612 '...' is obsolete"
|
||||
#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ...
|
||||
#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..."
|
||||
#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'"
|
||||
#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant"
|
||||
#pragma warning disable 8603 // Disable "CS8603 Possible null reference return"
|
||||
#pragma warning disable 8603 // Disable "CS8603 Possible null reference return"
|
||||
#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter"
|
||||
#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type"
|
@ -203,10 +203,4 @@ namespace {{ Namespace }}
|
||||
|
||||
}
|
||||
|
||||
#pragma warning restore 1591
|
||||
#pragma warning restore 1573
|
||||
#pragma warning restore 472
|
||||
#pragma warning restore 114
|
||||
#pragma warning restore 108
|
||||
#pragma warning restore 3016
|
||||
#pragma warning restore 8603
|
||||
{% template File.Footer %}
|
||||
|
@ -126,27 +126,47 @@ internal class JsonExceptionConverter : Newtonsoft.Json.JsonConverter
|
||||
private System.Collections.Generic.IDictionary<System.Reflection.PropertyInfo, string> GetExceptionProperties(System.Type exceptionType)
|
||||
{
|
||||
var result = new System.Collections.Generic.Dictionary<System.Reflection.PropertyInfo, string>();
|
||||
foreach (var property in System.Linq.Enumerable.Where(System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(exceptionType),
|
||||
p => p.GetMethod?.IsPublic == true))
|
||||
foreach (var property in System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(exceptionType))
|
||||
{
|
||||
if (property.GetMethod?.IsPublic != true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute<Newtonsoft.Json.JsonPropertyAttribute>(property);
|
||||
var propertyName = attribute != null ? attribute.PropertyName : property.Name;
|
||||
|
||||
if (!System.Linq.Enumerable.Contains(new[] { "Message", "StackTrace", "Source", "InnerException", "Data", "TargetSite", "HelpLink", "HResult" }, propertyName))
|
||||
result[property] = propertyName;
|
||||
|
||||
switch (propertyName)
|
||||
{
|
||||
case "Message":
|
||||
case "StackTrace":
|
||||
case "Source":
|
||||
case "InnerException":
|
||||
case "Data":
|
||||
case "TargetSite":
|
||||
case "HelpLink":
|
||||
case "HResult":
|
||||
break;
|
||||
default:
|
||||
result[property] = propertyName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetExceptionFieldValue(Newtonsoft.Json.Linq.JObject jObject, string propertyName, object value, string fieldName, Newtonsoft.Json.Serialization.IContractResolver resolver, Newtonsoft.Json.JsonSerializer serializer)
|
||||
{
|
||||
var field = System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(System.Exception)).GetDeclaredField(fieldName);
|
||||
var jsonPropertyName = resolver is Newtonsoft.Json.Serialization.DefaultContractResolver ? ((Newtonsoft.Json.Serialization.DefaultContractResolver)resolver).GetResolvedPropertyName(propertyName) : propertyName;
|
||||
var property = System.Linq.Enumerable.FirstOrDefault(jObject.Properties(), p => System.String.Equals(p.Name, jsonPropertyName, System.StringComparison.OrdinalIgnoreCase));
|
||||
if (property != null)
|
||||
private void SetExceptionFieldValue(Newtonsoft.Json.Linq.JObject jObject, string propertyName, object value, string fieldName, Newtonsoft.Json.Serialization.IContractResolver resolver, Newtonsoft.Json.JsonSerializer serializer)
|
||||
{
|
||||
var fieldValue = property.Value.ToObject(field.FieldType, serializer);
|
||||
field.SetValue(value, fieldValue);
|
||||
var field = System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(System.Exception)).GetDeclaredField(fieldName);
|
||||
var jsonPropertyName = resolver is Newtonsoft.Json.Serialization.DefaultContractResolver ? ((Newtonsoft.Json.Serialization.DefaultContractResolver)resolver).GetResolvedPropertyName(propertyName) : propertyName;
|
||||
foreach (var property in jObject.Properties())
|
||||
{
|
||||
if (System.String.Equals(p.Name, jsonPropertyName, System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var fieldValue = property.Value.ToObject(field.FieldType, serializer);
|
||||
field.SetValue(value, fieldValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user