-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
housekeeping: add .net core 3.0 support (#349)
- Loading branch information
1 parent
1a00028
commit 99c619a
Showing
30 changed files
with
1,375 additions
and
16 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
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
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
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
2 changes: 1 addition & 1 deletion
2
src/Splat.SimpleInjector.Tests/Splat.SimpleInjector.Tests.csproj
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
893 changes: 893 additions & 0 deletions
893
src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.0.approved.txt
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,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
57
src/Splat/Platforms/netcoreapp3/Bitmaps/BitmapSourceBitmap.cs
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,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
85
src/Splat/Platforms/netcoreapp3/Bitmaps/PlatformBitmapLoader.cs
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,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(); | ||
} | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.