Skip to content

Commit

Permalink
#544 target framework changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Sep 7, 2020
1 parent 09418e5 commit 63f61cb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 116 deletions.
4 changes: 2 additions & 2 deletions Test/Flurl.Test/Flurl.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net471;netcoreapp2.0;</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.0;</TargetFrameworks>

This comment has been minimized.

Copy link
@gitfool

gitfool Sep 7, 2020

Contributor

FWIW, I'd also replace tests using netcoreapp2.0 with netcoreapp3.1. See out of support .NET Core releases.

This comment has been minimized.

Copy link
@tmenier

tmenier Sep 8, 2020

Author Owner

Agreed. Less important since it's just the test proj but I think newest platforms makes sense so going with netcoreapp3.1;net48.

I also have these things called PackageTesters which are not automated and are probably less valuable than they were back when NuGet had so many quirks, but I do still like having an easy way to confirm end-to-end that I can install a package on a given platform and it works. I'm taking the opposite approach here and going with oldest: net461 and netcoreapp2.0. (No strong reason other than making them different than the unit tests.)

<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp2.0</TargetFrameworks>

This comment has been minimized.

Copy link
@gitfool

gitfool Sep 7, 2020

Contributor

I don't understand why this condition is needed. I would remove it.

This comment has been minimized.

Copy link
@tmenier

tmenier Sep 8, 2020

Author Owner

Agreed. Missed that.

</PropertyGroup>

Expand All @@ -19,7 +19,7 @@
<ProjectReference Include="..\..\src\Flurl.Http\Flurl.Http.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net471'">
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Net.Http" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
Expand Down
25 changes: 1 addition & 24 deletions src/Flurl.Http/FileUtil.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
using System.IO;
#if NETSTANDARD1_1
using System.Linq;
#endif
using System.Threading.Tasks;

namespace Flurl.Http
{
internal static class FileUtil
{
#if NETSTANDARD1_1
internal static string GetFileName(string path) {
return path?.Split(PCLStorage.PortablePath.DirectorySeparatorChar).Last();
}

internal static string CombinePath(params string[] paths) {
return PCLStorage.PortablePath.Combine(paths);
}

internal static async Task<Stream> OpenReadAsync(string path, int bufferSize) {
var file = await PCLStorage.FileSystem.Current.GetFileFromPathAsync(path).ConfigureAwait(false);
return await file.OpenAsync(PCLStorage.FileAccess.Read).ConfigureAwait(false);
}

internal static async Task<Stream> OpenWriteAsync(string folderPath, string fileName, int bufferSize) {
var folder = await PCLStorage.FileSystem.Current.LocalStorage.CreateFolderAsync(folderPath, PCLStorage.CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
var file = await folder.CreateFileAsync(fileName, PCLStorage.CreationCollisionOption.ReplaceExisting).ConfigureAwait(false);
return await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite).ConfigureAwait(false);
}
#else
internal static string GetFileName(string path) {
return Path.GetFileName(path);
}
Expand All @@ -45,7 +22,7 @@ internal static Task<Stream> OpenWriteAsync(string folderPath, string fileName,
var filePath = Path.Combine(folderPath, fileName);
return Task.FromResult<Stream>(new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize, useAsync: true));
}
#endif

/// <summary>
/// Replaces invalid path characters with underscores.
/// </summary>
Expand Down
42 changes: 8 additions & 34 deletions src/Flurl.Http/Flurl.Http.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;net46;netstandard1.1;netstandard1.3;netstandard2.0;</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.1;netstandard1.3;netstandard2.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Flurl.Http</PackageId>
<Version>3.0.0-pre4</Version>
Expand All @@ -14,7 +12,7 @@
<RepositoryUrl>https://github.com/tmenier/Flurl.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>httpclient rest json http fluent url uri tdd assert async</PackageTags>
<PackageTags>rest http httpclient json url uri tdd</PackageTags>
<PackageReleaseNotes>https://github.com/tmenier/Flurl/releases</PackageReleaseNotes>
<IncludeProjectPriFile>false</IncludeProjectPriFile>
</PropertyGroup>
Expand All @@ -26,7 +24,11 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\Flurl.Http.xml</DocumentationFile>
<DocumentationFile>bin\Release\Flurl.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\Flurl.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -36,39 +38,11 @@
<None Include="..\..\icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1'">
<PackageReference Include="PCLStorage" Version="1.0.2" />
</ItemGroup>

<PropertyGroup>
<PackageTargetFallback Condition="'$(TargetFramework)'=='netstandard1.1'">portable-net45+win8+wp8</PackageTargetFallback>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net45|AnyCPU'">
<DocumentationFile>bin\Debug\Flurl.Http.xml</DocumentationFile>
<WarningsAsErrors />
<NoWarn />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net45|AnyCPU'">
<WarningsAsErrors />
<NoWarn />
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Net.Http" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Flurl.Http/FlurlResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public async Task<string> GetStringAsync() {
_capturedBody?.ToString();
}

#if NETSTANDARD1_3 || NETSTANDARD2_0
#if NETSTANDARD2_0
// https://stackoverflow.com/questions/46119872/encoding-issues-with-net-core-2 (#86)
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
Expand Down
11 changes: 0 additions & 11 deletions src/Flurl.Http/Testing/HttpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ namespace Flurl.Http.Testing
/// An object whose existence puts Flurl.Http into test mode where actual HTTP calls are faked. Provides a response
/// queue, call log, and assertion helpers for use in Arrange/Act/Assert style tests.
/// </summary>
#if NET45
[Serializable]
#endif
public class HttpTest : HttpTestSetup, IDisposable
{
private readonly ConcurrentQueue<FlurlCall> _calls = new ConcurrentQueue<FlurlCall>();
Expand Down Expand Up @@ -106,17 +104,8 @@ public void Dispose() {
SetCurrentTest(null);
}

#if NET45
private static void SetCurrentTest(HttpTest test) => System.Runtime.Remoting.Messaging.CallContext.LogicalSetData("FlurlHttpTest", test);
private static HttpTest GetCurrentTest() => System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("FlurlHttpTest") as HttpTest;
#elif NETSTANDARD1_1
private static HttpTest _test;
private static void SetCurrentTest(HttpTest test) => _test = test;
private static HttpTest GetCurrentTest() => _test;
#else
private static readonly System.Threading.AsyncLocal<HttpTest> _test = new System.Threading.AsyncLocal<HttpTest>();
private static void SetCurrentTest(HttpTest test) => _test.Value = test;
private static HttpTest GetCurrentTest() => _test.Value;
#endif
}
}
25 changes: 3 additions & 22 deletions src/Flurl/Flurl.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net40;netstandard1.0;netstandard1.3;netstandard2.0;</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.0;netstandard1.3;netstandard2.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Flurl</PackageId>
<Version>3.0.0-pre4</Version>
Expand All @@ -29,36 +27,19 @@
<DocumentationFile>bin\Release\Flurl.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net40|AnyCPU'">
<WarningsAsErrors />
<NoWarn />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\Flurl.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net40|AnyCPU'">
<WarningsAsErrors />
<NoWarn />
</PropertyGroup>

<ItemGroup>
<None Include="..\..\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

</Project>
29 changes: 7 additions & 22 deletions src/Flurl/Util/CommonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public static string ToInvariantString(this object obj) {
obj == null ? null :
obj is DateTime dt ? dt.ToString("o", CultureInfo.InvariantCulture) :
obj is DateTimeOffset dto ? dto.ToString("o", CultureInfo.InvariantCulture) :
#if !NETSTANDARD1_0
obj is IConvertible c ? c.ToString(CultureInfo.InvariantCulture) :
#endif
obj is IFormattable f ? f.ToString(null, CultureInfo.InvariantCulture) :
obj.ToString();
}
Expand All @@ -70,31 +68,18 @@ private static IEnumerable<KeyValuePair<string, object>> StringToKV(string s) {
return Url.ParseQueryParams(s).Select(p => new KeyValuePair<string, object>(p.Name, p.Value));
}

private static IEnumerable<KeyValuePair<string, object>> ObjectToKV(object obj) {
#if NETSTANDARD1_0
return from prop in obj.GetType().GetRuntimeProperties()
let getter = prop.GetMethod
where getter?.IsPublic == true
let val = getter.Invoke(obj, null)
select new KeyValuePair<string, object>(prop.Name, val);
#else
return from prop in obj.GetType().GetProperties()
let getter = prop.GetGetMethod(false)
where getter != null
let val = getter.Invoke(obj, null)
select new KeyValuePair<string, object>(prop.Name, val);
#endif
}
private static IEnumerable<KeyValuePair<string, object>> ObjectToKV(object obj) =>
from prop in obj.GetType().GetProperties()
let getter = prop.GetGetMethod(false)
where getter != null
let val = getter.Invoke(obj, null)
select new KeyValuePair<string, object>(prop.Name, val);

private static IEnumerable<KeyValuePair<string, object>> CollectionToKV(IEnumerable col) {
bool TryGetProp(object obj, string name, out object value) {
#if NETSTANDARD1_0
var prop = obj.GetType().GetRuntimeProperty(name);
var field = obj.GetType().GetRuntimeField(name);
#else
var prop = obj.GetType().GetProperty(name);
var field = obj.GetType().GetField(name);
#endif

if (prop != null) {
value = prop.GetValue(obj, null);
return true;
Expand Down

0 comments on commit 63f61cb

Please sign in to comment.