Uri.QueryString.Composer
1.0.1
See the version list below for details.
dotnet add package Uri.QueryString.Composer --version 1.0.1
NuGet\Install-Package Uri.QueryString.Composer -Version 1.0.1
<PackageReference Include="Uri.QueryString.Composer" Version="1.0.1" />
paket add Uri.QueryString.Composer --version 1.0.1
#r "nuget: Uri.QueryString.Composer, 1.0.1"
// Install Uri.QueryString.Composer as a Cake Addin #addin nuget:?package=Uri.QueryString.Composer&version=1.0.1 // Install Uri.QueryString.Composer as a Cake Tool #tool nuget:?package=Uri.QueryString.Composer&version=1.0.1
Uri QueryString Composer
Have you ever needed to make an http call and had to assemble a giant query string entirely manually?
I hope you never have to. 😆
What is it?
It's a simple library that allows you to turn a class into a query string for https calls.
Usage
The implementation is available through a static class QueryStringComposer
.
The two available overloads perform the same conversion.
String overload
Code result: http://localhost?SomeName=Victor&SomeAge=20
const string baseUrl = "http://localhost";
var queryObject = new YourClass
{
SomeName = "Victor",
SomaAge = 20
};
var result = QueryStringComposer.Compose(baseUrl, queryObject);
Uri overload
Code result: http://localhost?SomeName=Victor,Juan&SomeAge=20,21
var uri = new Uri("http://localhost");
// Some Uri Changes
var queryObject = new YourClass
{
SomeNames = new List<string> { "Victor", "Juan" },
SomaAges = new List<int> { 20, 21 }
};
var result = QueryStringComposer.Compose(uri, queryObject);
Attributes
QueryStringKeyNameAttribute
In case you need to pass a custom value as a key and don't want to mess up your code with non-standard names. You can use the QueryStringKeyNameAttribute
attribute for this.
Code result: http://localhost?user_name=Jorge
const string baseUrl = "http://localhost";
var queryObject = new YourClass
{
UserName = "Jorge",
};
var result = QueryStringComposer.Compose(uri, queryObject);
class YourClass
{
[QueryStringKeyName("user_name")]
public string UserName { get; set; }
}
QueryStringIgnoreAttribute
In case you only need to ignore one property and don't want to create a new class for it. You can use the QueryStringIgnoreAttribute
attribute for this.
Code result: http://localhost?Login=victorvhn
const string baseUrl = "http://localhost";
var queryObject = new YourClass
{
Login = "victorvhn",
Password = "d74ff0ee8da3b9806b18c8"
};
var result = QueryStringComposer.Compose(uri, queryObject);
class YourClass
{
public string Login { get; set; }
[QueryStringIgnore]
public string Password { get; set; }
}
Attention when using
Some types are not supported for conversion:
- Complex Lists.
- Complex Dictionaries.
Providing a dictionary to compose, the values will not be converted.
Code result: http://localhost?key1=value1&key2=value2
const string baseUrl = "http://localhost";
var dic = new Dictionary<string, string>
{
{ "key1", "value1" },
{ "key2", "value2" }
};
var result = QueryStringComposer.Compose(baseUrl, dic);
Package
License
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.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.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.
It's a simple library that allows you to turn a class into a query string for https calls.