Rmg.AspNetCore.ByXmlSerializer
1.0.0
dotnet add package Rmg.AspNetCore.ByXmlSerializer --version 1.0.0
NuGet\Install-Package Rmg.AspNetCore.ByXmlSerializer -Version 1.0.0
<PackageReference Include="Rmg.AspNetCore.ByXmlSerializer" Version="1.0.0" />
paket add Rmg.AspNetCore.ByXmlSerializer --version 1.0.0
#r "nuget: Rmg.AspNetCore.ByXmlSerializer, 1.0.0"
// Install Rmg.AspNetCore.ByXmlSerializer as a Cake Addin #addin nuget:?package=Rmg.AspNetCore.ByXmlSerializer&version=1.0.0 // Install Rmg.AspNetCore.ByXmlSerializer as a Cake Tool #tool nuget:?package=Rmg.AspNetCore.ByXmlSerializer&version=1.0.0
ByXmlSerializer
Formatter which allows mixed use of XmlSerializer
, DataContractSerializer
, and JsonSerializer
. Each
action can "opt-in" to XmlSerializer
by returning ByXmlSerializer<T>
(or ActionResult<ByXmlSerializer<T>>
et alia).
Example use
Add a reference in csproj:
<ItemGroup>
<PackageReference Include="Rmg.AspNetCore.ByXmlSerializer" Version="1.0.0" />
</ItemGroup>
Enable the formatter by adding it before adding DCS in Program.cs
:
using Rmg.AspNetCore;
// ...snip...
builder.Services.AddControllers()
.AddByXmlSerializerFormatters()
.AddXmlDataContractSerializerFormatters();
// ...snip...
"Mark" specific actions as preferring XmlSerializer
by returning or accepting ByXmlSerializer<T>
:
[HttpGet("xs1")]
public ByXmlSerializer<WeatherForecast> GetExample1()
{
// ByXmlSerializer<T> is implicitly creatable from T
return new WeatherForecast();
}
[HttpGet("xs2")]
public ActionResult<ByXmlSerializer<WeatherForecast>> GetExample2()
{
// or use an extension method on ControllerBase to coerce type
return this.ByXmlSerailizer(new WeatherForecast());
}
[HttpGet("xs3")]
public ActionResult<ByXmlSerializer<WeatherForecast>> GetExample3()
{
// or explicitly construct
return StatusCode(400, new ByXmlSerializer<WeatherForecast>(new ()));
}
[HttpPost("pe1")]
public ByXmlSerializer<WeatherForecast> PostExample1([FromBody] ByXmlSerializer<ForecastArea> area)
{
// ByXmlSerializer<T> is implicitly unwrappable to T
ForecastArea unwrappedArea = area;
return new WeatherForecast(unwrappedArea);
}
[HttpPost("pe2")]
public ByXmlSerializer<WeatherForecast> GetExample5([FromBody] ByXmlSerializer<ForecastArea> area)
{
// or use .Value directly
return new WeatherForecast(area.Value);
}
Methods marked with ByXmlSerializer<T>
can still use other formatters (e.g.: System.Text.Json) without
issue. Only formatters which also read text/xml
or application/xml
are superseded.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 164 | 3/11/2024 |