Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

housekeeping: add .net core 3.0 support #349

Merged
merged 16 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ resources:
endpoint: reactiveui

jobs:
- template: Azure/azure-pipelines.yml@templates # Template reference
- template: Azure/azure-pipelines.yml@templates # Template reference
parameters:
dotNetVersion: '3.0.100-preview6-012264'
runMacBuild: false

4 changes: 2 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#load nuget:https://www.myget.org/F/reactiveui/api/v2?package=ReactiveUI.Cake.Recipe&prerelease
#load nuget:https://www.myget.org/F/reactiveui?package=ReactiveUI.Cake.Recipe&prerelease

Environment.SetVariableNames();

Expand Down Expand Up @@ -33,6 +33,6 @@ BuildParameters.SetParameters(context: Context,
artifactsDirectory: "./artifacts",
sourceDirectory: "./src");

ToolSettings.SetToolSettings(context: Context);
ToolSettings.SetToolSettings(context: Context, usePrereleaseMsBuild: true);

Build.Run();
4 changes: 2 additions & 2 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>

<ItemGroup Condition="$(IsTestProject)">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
Expand Down Expand Up @@ -68,8 +68,8 @@

<ItemGroup>
<PackageReference Include="stylecop.analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="2.1.0-rc" PrivateAssets="All" />
<PackageReference Condition="'$(OS)' == 'Windows_NT'" Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Directory.build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<DefineConstants>$(DefineConstants);NET_45;XAML</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('uap'))">
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<DefineConstants>$(DefineConstants);NETFX_CORE;XAML;WINDOWS_UWP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS'))">
Expand Down
2 changes: 1 addition & 1 deletion src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>

<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion src/Splat.DryIoc.Tests/Splat.DryIoc.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
</PropertyGroup>
Expand Down

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions src/Splat.Tests/API/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See the LICENSE file in the project root for full license information.

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -42,14 +43,45 @@ private static void CheckApproval(Assembly assembly, [CallerMemberName]string me
var approvedFileName = Path.Combine(sourceDirectory, $"ApiApprovalTests.{memberName}.{targetFrameworkName}.approved.txt");
var receivedFileName = Path.Combine(sourceDirectory, $"ApiApprovalTests.{memberName}.{targetFrameworkName}.received.txt");

var approvedPublicApi = File.ReadAllText(approvedFileName);
string approvedPublicApi = string.Empty;

if (File.Exists(approvedFileName))
{
approvedPublicApi = File.ReadAllText(approvedFileName);
}

var receivedPublicApi = Filter(ApiGenerator.GeneratePublicApi(assembly));

if (!string.Equals(receivedPublicApi, approvedPublicApi, StringComparison.InvariantCulture))
{
File.WriteAllText(receivedFileName, receivedPublicApi);
ShouldlyConfiguration.DiffTools.GetDiffTool().Open(receivedFileName, approvedFileName, true);
try
{
ShouldlyConfiguration.DiffTools.GetDiffTool().Open(receivedFileName, approvedFileName, true);
}
catch (ShouldAssertException)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
Arguments = $"\"{approvedFileName}\" \"{receivedFileName}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
#if NET_461
process.StartInfo.FileName = "FC";
#else
process.StartInfo.FileName = "diff";
#endif
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

throw new Exception("Invalid API configuration: " + Environment.NewLine + output);
}
}

Assert.Equal(approvedPublicApi, receivedPublicApi);
Expand Down
2 changes: 1 addition & 1 deletion src/Splat.Tests/Splat.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;MonoAndroid81</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;MonoAndroid81</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
</PropertyGroup>
Expand Down
35 changes: 35 additions & 0 deletions src/Splat/Platforms/netcoreapp3/Bitmaps/BitmapMixins.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Windows.Media.Imaging;

namespace Splat
{
/// <summary>
/// Extension methods to assist with dealing with Bitmaps.
/// </summary>
public static class BitmapMixins
{
/// <summary>
/// Converts <see cref="IBitmap"/> to a native type.
/// </summary>
/// <param name="value">The bitmap to convert.</param>
/// <returns>A <see cref="BitmapSource"/> bitmap.</returns>
public static IBitmap FromNative(this BitmapSource value)
{
return new BitmapSourceBitmap(value);
}

/// <summary>
/// Converts a <see cref="BitmapSource"/> to a splat <see cref="IBitmap"/>.
/// </summary>
/// <param name="value">The native bitmap to convert from.</param>
/// <returns>A <see cref="IBitmap"/> bitmap.</returns>
public static BitmapSource ToNative(this IBitmap value)
{
return ((BitmapSourceBitmap)value).Inner;
}
}
}
57 changes: 57 additions & 0 deletions src/Splat/Platforms/netcoreapp3/Bitmaps/BitmapSourceBitmap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.IO;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace Splat
{
/// <summary>
/// A bitmap that wraps a <see cref="BitmapSourceBitmap"/>.
/// </summary>
internal sealed class BitmapSourceBitmap : IBitmap
{
/// <summary>
/// Initializes a new instance of the <see cref="BitmapSourceBitmap"/> class.
/// </summary>
/// <param name="bitmap">The platform native bitmap we are wrapping.</param>
public BitmapSourceBitmap(BitmapSource bitmap)
{
Inner = bitmap;
}

/// <inheritdoc />
public float Width => (float)Inner.Width;

/// <inheritdoc />
public float Height => (float)Inner.Height;

/// <summary>
/// Gets the platform <see cref="BitmapSource"/>.
/// </summary>
public BitmapSource Inner { get; private set; }

/// <inheritdoc />
public Task Save(CompressedBitmapFormat format, float quality, Stream target)
{
return Task.Run(() =>
{
var encoder = format == CompressedBitmapFormat.Jpeg ?
new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } :
(BitmapEncoder)new PngBitmapEncoder();

encoder.Frames.Add(BitmapFrame.Create(Inner));
encoder.Save(target);
});
}

/// <inheritdoc />
public void Dispose()
{
Inner = null;
}
}
}
85 changes: 85 additions & 0 deletions src/Splat/Platforms/netcoreapp3/Bitmaps/PlatformBitmapLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Splat
{
/// <summary>
/// A XAML based platform bitmap loader which will load our bitmaps for us.
/// </summary>
public class PlatformBitmapLoader : IBitmapLoader
{
/// <inheritdoc />
public Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight)
{
return Task.Run(() =>
{
var ret = new BitmapImage();

WithInit(ret, source =>
{
if (desiredWidth != null)
{
source.DecodePixelWidth = (int)desiredWidth;
}

if (desiredHeight != null)
{
source.DecodePixelHeight = (int)desiredHeight;
}

source.StreamSource = sourceStream;
source.CacheOption = BitmapCacheOption.OnLoad;
});

return (IBitmap)new BitmapSourceBitmap(ret);
});
}

/// <inheritdoc />
public Task<IBitmap> LoadFromResource(string resource, float? desiredWidth, float? desiredHeight)
{
return Task.Run(() =>
{
var ret = new BitmapImage();
WithInit(ret, x =>
{
if (desiredWidth != null)
{
x.DecodePixelWidth = (int)desiredWidth;
}

if (desiredHeight != null)
{
x.DecodePixelHeight = (int)desiredHeight;
}

x.UriSource = new Uri(resource, UriKind.RelativeOrAbsolute);
});

return (IBitmap)new BitmapSourceBitmap(ret);
});
}

/// <inheritdoc />
public IBitmap Create(float width, float height)
{
return new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Default, null));
}

private static void WithInit(BitmapImage source, Action<BitmapImage> block)
{
source.BeginInit();
block(source);
source.EndInit();
source.Freeze();
}
}
}
47 changes: 47 additions & 0 deletions src/Splat/Platforms/netcoreapp3/Colors/ColorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Windows.Media;

namespace Splat
{
/// <summary>
/// Provides extension methods for interacting with colors, to and from the XAML colors.
/// </summary>
public static class ColorExtensions
{
/// <summary>
/// Converts a <see cref="System.Drawing.Color"/> to a XAML native color.
/// </summary>
/// <param name="value">The System.Drawing.Color to convert.</param>
/// <returns>A native XAML color.</returns>
public static Color ToNative(this System.Drawing.Color value)
{
return Color.FromArgb(value.A, value.R, value.G, value.B);
}

/// <summary>
/// Converts a <see cref="System.Drawing.Color"/> into the cocoa native <see cref="SolidColorBrush"/>.
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="SolidColorBrush"/> generated.</returns>
public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value)
{
var ret = new SolidColorBrush(value.ToNative());
ret.Freeze();
return ret;
}

/// <summary>
/// Converts a <see cref="SolidColorBrush"/> into the XAML <see cref="System.Drawing.Color"/>.
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="System.Drawing.Color"/> generated.</returns>
public static System.Drawing.Color FromNative(this Color value)
{
return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
}
}
}
Loading