-
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.
Added Microsoft.Maui.Extensions project and the JsonUriStringConverte…
…r & JsonLocaleConverter JsonConverter classes and the UriOrString class.
- Loading branch information
Showing
18 changed files
with
390 additions
and
22 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
{ | ||
"dotnet-test-explorer.testProjectPath": "**/*Tests.@(csproj|vbproj|fsproj)" | ||
} | ||
"dotnet-test-explorer.testProjectPath": "**/*Tests.@(csproj|vbproj|fsproj)", | ||
"sonarlint.connectedMode.project": { | ||
"connectionId": "dgmjr-io", | ||
"projectKey": "dgmjr-io_Dgmjr.System.Extensions" | ||
} | ||
} |
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,21 @@ | ||
<!-- | ||
* Directory.Build.props | ||
* | ||
* Created: 2023-01-11-05:08:45 | ||
* Modified: 2023-01-11-11:48:02 | ||
* | ||
* Author: David G. Moore, Jr. <[email protected]> | ||
* | ||
* Copyright © 2022-2023 David G. Moore, Jr., All Rights Reserved | ||
* License: MIT (https://opensource.org/licenses/MIT) | ||
--> | ||
|
||
<Project> | ||
<Import Project="Sdk.props" Sdk="DgmjrSdk" Condition="'$(DgmjrSdkProps)' == '' And '$(IsInnerBuild)' != 'true'" /> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks> | ||
<DgmjrSdkProps>$(MSBuildThisFileDirectory)Sdk.props</DgmjrSdkProps> | ||
<!--<InheritedDirectoryBuildProps>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</InheritedDirectoryBuildProps>--> | ||
</PropertyGroup> | ||
<!--<Import Project="$(InheritedDirectoryBuildProps)" Condition="Exists('$(InheritedDirectoryBuildProps)')" />--> | ||
</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,20 @@ | ||
<!-- | ||
* Directory.Build.targets | ||
* | ||
* Created: 2023-01-11-05:08:45 | ||
* Modified: 2023-01-11-11:47:51 | ||
* | ||
* Author: David G. Moore, Jr. <[email protected]> | ||
* | ||
* Copyright © 2022-2023 David G. Moore, Jr., All Rights Reserved | ||
* License: MIT (https://opensource.org/licenses/MIT) | ||
--> | ||
|
||
<Project> | ||
<Import Project="Sdk.targets" Sdk="DgmjrSdk" Condition="'$(DgmjrSdkTargets)' == '' And '$(IsInnerBuild)' != 'true'" /> | ||
<PropertyGroup> | ||
<DgmjrSdkTargets>$(MSBuildThisFileDirectory)Sdk.targets</DgmjrSdkTargets> | ||
<!--<InheritedDirectoryBuildTargets>$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))</InheritedDirectoryBuildTargets>--> | ||
</PropertyGroup> | ||
<!--<Import Project="$(InheritedDirectoryBuildTargets)" Condition="Exists('$(InheritedDirectoryBuildTargets)')" />--> | ||
</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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Description>Extension methods for Microsoft MAUI framework</Description> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Maui.Graphics" /> | ||
</ItemGroup> | ||
</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,42 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}" | ||
ProjectSection(SolutionItems) = preProject | ||
..\Directory.Build.props = ..\Directory.Build.props | ||
..\Directory.Build.targets = ..\Directory.Build.targets | ||
..\..\..\..\global.json = ..\..\..\..\global.json | ||
..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\Packages\Versions.Local.props | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Microsoft.Maui.Extensions", "Dgmjr.Microsoft.Maui.Extensions.csproj", "{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Local|Any CPU = Local|Any CPU | ||
Debug|Any CPU = Debug|Any CPU | ||
Testing|Any CPU = Testing|Any CPU | ||
Staging|Any CPU = Staging|Any CPU | ||
Production|Any CPU = Production|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Local|Any CPU.ActiveCfg = Local|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Local|Any CPU.Build.0 = Local|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Testing|Any CPU.ActiveCfg = Testing|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Testing|Any CPU.Build.0 = Testing|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Staging|Any CPU.ActiveCfg = Staging|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Staging|Any CPU.Build.0 = Staging|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Production|Any CPU.ActiveCfg = Local|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Production|Any CPU.Build.0 = Local|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D2AEFA3C-FCDD-4126-98C0-BB0BD5D9D071}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {3C15FE54-9A1C-43C9-8C8D-7AB7FA71BD87} | ||
EndGlobalSection | ||
EndGlobal |
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,36 @@ | ||
namespace Microsoft.Maui.Graphics; | ||
|
||
using Microsoft.Maui.Graphics.Platform; | ||
using System.Reflection; | ||
|
||
public static class IImageExtensions | ||
{ | ||
public static Size GetDimensions(this IImage image, int maxDimension = int.MaxValue) | ||
{ | ||
var width = image.Width; | ||
var height = image.Height; | ||
if (width > maxDimension || height > maxDimension) | ||
{ | ||
var ratio = width / (double)height; | ||
if (ratio > 1) | ||
{ | ||
width = maxDimension; | ||
height = (int)(width / ratio); | ||
} | ||
else | ||
{ | ||
height = maxDimension; | ||
width = (int)(height * ratio); | ||
} | ||
} | ||
return new Size(width, height); | ||
} | ||
|
||
public static IImage ToImage(this Stream stream) => PlatformImage.FromStream(stream); | ||
|
||
public static Uri ToDataUri(this IImage image, string mimeType = "image/png") | ||
{ | ||
var bytes = image.AsBytes(); | ||
return new Uri($"data:{mimeType};base64,{Convert.ToBase64String(bytes)}"); | ||
} | ||
} |
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 @@ | ||
--- | ||
date: 2023-07-13T05:44:46:00.048Z | ||
description: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, yadda, yadda, yadda... | ||
keywords: | ||
- IP | ||
- copyright | ||
- license | ||
- mit | ||
permissions: | ||
- commercial-use | ||
- modifications | ||
- distribution | ||
- private-use | ||
conditions: | ||
- include-copyright | ||
limitations: | ||
- liability | ||
- warranty | ||
lastmod: 2023-08-29T17:13:51:00.216Z | ||
license: MIT | ||
slug: mit-license | ||
title: MIT License | ||
type: license | ||
--- | ||
|
||
# MIT License | ||
|
||
## Copyright © 2022-2023 [David G. Moore, Jr.](mailto:[email protected] "Send David an email") ([@dgmjr](https://github.com/dgmjr "Contact david on GitHub")), All Rights Reserved | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
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,21 @@ | ||
--- | ||
title: Microsoft MAUI Extensions | ||
lastmod: 2023-23-22T18:23:41.1955-05:00Z | ||
date: 2023-23-22T18:23:41.1956-05:00Z | ||
license: MIT | ||
slug: Dgmjr.Microsoft.Maui.Extensions-readme | ||
version: | ||
authors: | ||
- dgmjr; | ||
description: Extension methods for Microsoft MAUI framework | ||
keywords: | ||
- Dgmjr.Microsoft.Maui.Extensions | ||
- dgmjr | ||
- dgmjr-io | ||
type: readme | ||
--- | ||
|
||
# Microsoft MAUI Extensions | ||
|
||
This package contains extension methods for the Microsoft MAUI framework. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace System.Globalization; | ||
|
||
using System.Text.Json.Serialization; | ||
using System.Text.Json; | ||
using Jso = System.Text.Json.JsonSerializerOptions; | ||
|
||
public class JsonLocaleConverter | ||
: System.Text.Json.Serialization.JsonConverter<System.Globalization.CultureInfo> | ||
{ | ||
public override System.Globalization.CultureInfo Read( | ||
ref Utf8JsonReader reader, | ||
type typeToConvert, | ||
Jso options | ||
) | ||
{ | ||
if (reader.TokenType == JsonTokenType.String) | ||
{ | ||
try | ||
{ | ||
return System.Globalization.CultureInfo.CreateSpecificCulture(reader.GetString()); | ||
} | ||
catch | ||
{ | ||
return System.Globalization.CultureInfo.InvariantCulture; | ||
} | ||
} | ||
else | ||
{ | ||
return System.Globalization.CultureInfo.InvariantCulture; | ||
} | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
System.Globalization.CultureInfo value, | ||
Jso options | ||
) | ||
{ | ||
writer.WriteStringValue(value.Name); | ||
} | ||
} |
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 @@ | ||
namespace System; | ||
|
||
using System.Text.Json.Serialization; | ||
using System.Text.Json; | ||
using Jso = System.Text.Json.JsonSerializerOptions; | ||
|
||
public class JsonIntegerToTimeSpanConverter : JsonConverter<duration> | ||
{ | ||
public override duration Read(ref Utf8JsonReader reader, type typeToConvert, Jso options) | ||
{ | ||
if (reader.TokenType != JTokenType.Number) | ||
{ | ||
throw new JsonException(); | ||
} | ||
return duration.FromSeconds(reader.GetInt64()); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, duration value, Jso options) | ||
{ | ||
writer.WriteNumberValue(value.TotalSeconds); | ||
} | ||
} |
Oops, something went wrong.