forked from tmenier/Flurl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
304 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ packages | |
*.suo | ||
*.nupkg | ||
*.DotSettings.user | ||
*.xproj.user | ||
.vs | ||
*.lock.json | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@echo off | ||
|
||
set workDir=%1 | ||
set publishSpec=%2 | ||
set publishDir=%3 | ||
|
||
cd %workDir% | ||
if not exist "%publishDir%" mkdir "%publishDir%" | ||
call NuGet.exe pack %publishSpec% -OutputDirectory %publishDir% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>52c8c00d-9bd2-4642-b103-f0a8c564fe05</ProjectGuid> | ||
<RootNamespace>Flurl.Http.NETCore</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"title": "Flurl.Http.NETCore", | ||
|
||
"dependencies": { | ||
"Flurl": "1.1.0", | ||
"Newtonsoft.Json": "8.0.3" | ||
}, | ||
|
||
"compile": [ "../Flurl.Http.Shared/**/*.cs", "../Flurl.Http.NET45/**/*.cs" ], | ||
"compileExclude": [ "../**/AssemblyInfo.cs" ], | ||
|
||
"configurations": { | ||
"Release": { | ||
"compilationOptions": { | ||
"optimize": true | ||
} | ||
} | ||
}, | ||
|
||
"frameworks": { | ||
"dotnet54": { | ||
"dependencies": { | ||
"System.Dynamic.Runtime": "4.0.10", | ||
"System.IO.FileSystem": "4.0.0", | ||
"System.Net.Http": "4.0.0", | ||
"System.Text.RegularExpressions": "4.0.10", | ||
"System.Threading": "4.0.10" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>52ce5e08-8f02-4f75-8b64-8e00e3262a0f</ProjectGuid> | ||
<RootNamespace>Flurl.NETCore</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Flurl.Util | ||
{ | ||
public static class CommonExtensions | ||
{ | ||
/// <summary> | ||
/// Converts an object's public properties to a collection of string-based key-value pairs. If the object happens | ||
/// to be an IDictionary, the IDictionary's keys and values converted to strings and returned. | ||
/// </summary> | ||
/// <param name="obj">The object to parse into key-value pairs</param> | ||
/// <returns></returns> | ||
public static IEnumerable<KeyValuePair<string, object>> ToKeyValuePairs(this object obj) | ||
{ | ||
if (obj == null) | ||
throw new ArgumentNullException(nameof(obj)); | ||
|
||
return | ||
(obj is string) ? QueryParamCollection.Parse((string)obj) : | ||
(obj is IEnumerable) ? CollectionToKV((IEnumerable)obj) : | ||
ObjectToKV(obj); | ||
} | ||
|
||
/// <summary> | ||
/// Returns a string that represents the current object, using CultureInfo.InvariantCulture where possible. | ||
/// </summary> | ||
public static string ToInvariantString(this object obj) | ||
{ | ||
// inspired by: http://stackoverflow.com/a/19570016/62600 | ||
|
||
var c = obj as IConvertible; | ||
if (c != null) | ||
return c.ToString(CultureInfo.InvariantCulture); | ||
|
||
var f = obj as IFormattable; | ||
return f?.ToString(null, CultureInfo.InvariantCulture) ?? obj.ToString(); | ||
} | ||
|
||
private static IEnumerable<KeyValuePair<string, object>> ObjectToKV(object obj) | ||
{ | ||
return from prop in obj.GetType().GetProperties() | ||
let val = prop.GetValue(obj, null) | ||
select new KeyValuePair<string, object>(prop.Name, val); | ||
} | ||
|
||
private static IEnumerable<KeyValuePair<string, object>> CollectionToKV(IEnumerable col) | ||
{ | ||
// Accepts KeyValuePairs or any aribitray types that contain a property called "Key" or "Name" and a property called "Value". | ||
foreach (var item in col) | ||
{ | ||
if (item == null) | ||
continue; | ||
|
||
var type = item.GetType(); | ||
var keyProp = type.GetProperty("Key") ?? type.GetProperty("key") ?? type.GetProperty("Name") ?? type.GetProperty("name"); | ||
if (keyProp == null) | ||
throw new ArgumentException("Cannot parse " + type.Name + " to key-value pair. Type must contain a property called 'Key' or 'Name'."); | ||
|
||
var valProp = type.GetProperty("Value") ?? type.GetProperty("value"); | ||
if (valProp == null) | ||
throw new ArgumentException("Cannot parse " + type.Name + " to key-value pair. Type must contain a property called 'Value'."); | ||
|
||
var key = keyProp.GetValue(item, null); | ||
if (key == null) | ||
continue; | ||
|
||
var val = valProp.GetValue(item, null); | ||
yield return new KeyValuePair<string, object>(key.ToInvariantString(), val); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"title": "Flurl.NETCore", | ||
|
||
"compile": [ "../Flurl/**/*.cs" ], | ||
"compileExclude": [ "../**/AssemblyInfo.cs", "../Flurl/Util/CommonExtensions.cs" ], | ||
|
||
"configurations": { | ||
"Release": { | ||
"compilationOptions": { | ||
"optimize": true | ||
} | ||
} | ||
}, | ||
|
||
"frameworks": { | ||
"dotnet54": { | ||
"dependencies": { | ||
"System.Linq": "4.0.0", | ||
"System.Reflection.TypeExtensions": "4.0.0" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.