ByteDev.FormUrlEncoded 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ByteDev.FormUrlEncoded --version 1.0.0
NuGet\Install-Package ByteDev.FormUrlEncoded -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ByteDev.FormUrlEncoded" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ByteDev.FormUrlEncoded --version 1.0.0
#r "nuget: ByteDev.FormUrlEncoded, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ByteDev.FormUrlEncoded as a Cake Addin
#addin nuget:?package=ByteDev.FormUrlEncoded&version=1.0.0

// Install ByteDev.FormUrlEncoded as a Cake Tool
#tool nuget:?package=ByteDev.FormUrlEncoded&version=1.0.0

ByteDev.FormUrlEncoded

.NET Standard library for serializing and deserializing form URL encoded (application/x-www-form-urlencoded) data.

The form URL encoded format is a data format that encodes data as name-value pairs. It is most associated with web HTML forms and the visible web. However, it can also be used in other situations, for example as a form of data exchange by APIs. This library allows a consumer to serailize/deserialize data in the format without being tied to a web application environment such as ASP.NET.

Installation

ByteDev.FormUrlEncoded is hosted as a package on nuget.org. To install from the Package Manager Console in Visual Studio run:

Install-Package ByteDev.FormUrlEncoded

Further details can be found on the nuget page.

Release Notes

Releases follow semantic versioning.

Full details of the release notes can be viewed on GitHub.

Usage

FormUrlEncodedSerializer is the primary class in the library and allows the serialization and deserialization of form URL encoded content.

Serialization can be performed on any object. However, only the public instance properties of the object will have their values serialized.

It should be noted that when serialization of a object's property occurs the ToString method will be called on the property. The form URL encoded format is very flat so no serialization of inner types (e.g. a property's type's properties) or collection type's elements will occur.

The serializer supports:

  • All built in .NET types:
    • Reference types (object, string, etc.)
    • Value types (integral and floating point numeric types, enum, bool, char, struct)
  • Serialization specific settings via the SerializeOptions type parameter.
  • Deserialization specific settings via the DeserializeOptions type parameter.
  • Property attributes:
    • FormUrlEncodedPropertyNameAttribute which overrides the property name to use during serialization/deserialization.
    • FormUrlEncodedIgnoreAttribute which prevents a property from being used during serialization/deserialization.

Code Examples

The follow demonstrates simple serialization and deserialization of a type including the use of the FormUrlEncodedPropertyName and FormUrlEncodedIgnore attributes.

// Entitiy class (class you want to serialize/deserialize)

public class Employee
{
    public string Name { get; set; }

    public int Age { get; set; }

    [FormUrlEncodedPropertyName("emailAddress")]
    public string Email { get; set; }

    [FormUrlEncodedIgnore]
    public int PayGrade { get; set; }
}
// Serialize an object to a form URL encoded string

var employee = new Employee
{
    Name = "John Smith",
    Age = 50,
    Email = "john@somewhere.com",
    PayGrade = 5
};

string data = FormUrlEncodedSerializer.Serialize(employee);

// data == "Name=John+Smith&Age=50&emailAddress=john%40somewhere.com"
// Deserialize a form URL encoded string to an object

string data = "Name=John+Smith&Age=50&emailAddress=john%40somewhere.com&PayGrade=5";

Employee employee = FormUrlEncodedSerializer.Deserialize<Employee>(data);

// employee.Name == "John Smith"
// employee.Age == 50
// employee.Email == "john@somewhere.com"
// employee.PayGrade == 0

Serialize Options

Serializing options are supported via the SerializeOptions type parameter.

Options include:

  • Encode - Indicates if all public property names and values should be URI encoded when serializing. True by default.
  • EncodeSpaceAsPlus - Indicates if spaces should be encoded as a plus when serializing. True by default. Property Encode must be true for this property to have any affect.
  • IgnoreIfDefault - Indicates if a property should be ignored if it is set to it's default value. False by default.
  • IgnoreIfNull - Indicates if a property should be ignored if it is set to null. True by default. If property IgnoreIfDefault is set to true this property is ignored.
  • EnumHandling - Indicates how enums should be handled during serialization. Default handling is by number.

Deserialize Options

Deserializing options are supported via the DeserializeOptions type parameter.

Options include:

  • Decode - Indicates if all pair names and values should be URI decoded when deserializing. True by default.
  • DecodePlusAsSpace - Indicates if the plus sign should be decoded as a space when deserializing. True by default. Property Decode must be true for this property to have any affect.
  • EnumHandling - Indicates how enums should be handled during deserialization. Default handling is by number.
Product 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1.0 512 2/19/2024
1.0.0 3,357 6/17/2021