object serialization yo
This commit is contained in:
@@ -116,5 +116,15 @@ namespace FluentUriBuilder.Tests
|
||||
.WithParameter("supgf", "no22");
|
||||
Assert.Equal("http://awesome.com/?awesome=yodawg&supg=no2&supgf=no22", url.Uri.ToString());
|
||||
}
|
||||
[Fact]
|
||||
public void TestSerializedParameters()
|
||||
{
|
||||
var url = new UriBuilder("http://awesome.com")
|
||||
.WithSerializedObject(new {yo="dawg"});
|
||||
Assert.Equal("http://awesome.com/?yo=dawg", url.Uri.ToString());
|
||||
url = new UriBuilder("http://awesome.com")
|
||||
.WithSerializedObject(new {yo=""});
|
||||
Assert.Equal("http://awesome.com/?yo", url.Uri.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"net461": {},
|
||||
"net462": {},
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -10,6 +11,8 @@ namespace System
|
||||
{
|
||||
public static UriBuilder WithParameter(this UriBuilder bld, string key, params string[] values) => bld.WithParameter(key, valuesEnum: values);
|
||||
|
||||
public static UriBuilder WithParameter(this UriBuilder bld, string key, object value) => bld.WithParameter(key, new object[1] { value });
|
||||
|
||||
public static UriBuilder WithParameter(this UriBuilder bld, string key, IEnumerable<object> valuesEnum)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(key))
|
||||
@@ -74,5 +77,20 @@ namespace System
|
||||
bld.Scheme = predicate ? "https" : "http";
|
||||
return bld;
|
||||
}
|
||||
|
||||
#if netstandard15
|
||||
|
||||
public static UriBuilder WithSerializedObject(this UriBuilder bld, object serialize)
|
||||
{
|
||||
var types = serialize.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty);
|
||||
foreach(var type in types)
|
||||
{
|
||||
bld.WithParameter(type.Name, type.GetValue(serialize, null));
|
||||
}
|
||||
|
||||
return bld;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,37 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"packOptions": {
|
||||
"owners": [
|
||||
"Tommy Parnell"
|
||||
],
|
||||
"repository": {
|
||||
"url":"https://github.com/TerribleDev/UriBuilder.Fluent"
|
||||
},
|
||||
"summary": "Fluent extensions for UriBuilder",
|
||||
"tags": [
|
||||
"Url building",
|
||||
"Uri",
|
||||
"Uri building",
|
||||
"fluent",
|
||||
"extension"
|
||||
]
|
||||
"owners": [
|
||||
"Tommy Parnell"
|
||||
],
|
||||
"repository": {
|
||||
"url": "https://github.com/TerribleDev/UriBuilder.Fluent"
|
||||
},
|
||||
"summary": "Fluent extensions for UriBuilder",
|
||||
"tags": [
|
||||
"Url building",
|
||||
"Uri",
|
||||
"Uri building",
|
||||
"fluent",
|
||||
"extension"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
"authors": [
|
||||
"Tommy Parnell"
|
||||
"Tommy Parnell"
|
||||
],
|
||||
"frameworks": {
|
||||
"netstandard1.3": {
|
||||
"imports": "dnxcore50"
|
||||
"buildOptions": {
|
||||
"define": [ "netstandard13" ]
|
||||
}
|
||||
},
|
||||
"netstandard1.5": {
|
||||
"buildOptions": {
|
||||
"define": [ "netstandard15" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user