Skip to content

Commit 6fc488f

Browse files
committed
Added platform API helper for improvements to Uno specific areas.
1 parent 3f97089 commit 6fc488f

File tree

13 files changed

+248
-13
lines changed

13 files changed

+248
-13
lines changed

MADE.NET.sln

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MADE.UI.Styling", "src\MADE
7575
EndProject
7676
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MADE.UI.ViewManagement", "src\MADE.UI.ViewManagement\MADE.UI.ViewManagement.csproj", "{442D1E25-FFD1-405D-A1FC-40CAFCAD190C}"
7777
EndProject
78+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MADE.Foundation", "src\MADE.Foundation\MADE.Foundation.csproj", "{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}"
79+
EndProject
7880
Global
7981
GlobalSection(SharedMSBuildProjectFiles) = preSolution
8082
samples\MADE.Samples\MADE.Samples.Shared\MADE.Samples.Shared.projitems*{04f1b32d-9056-43fc-b4c2-b8c5481bdacb}*SharedItemsImports = 4
@@ -1843,6 +1845,62 @@ Global
18431845
{442D1E25-FFD1-405D-A1FC-40CAFCAD190C}.Release|x64.Build.0 = Release|Any CPU
18441846
{442D1E25-FFD1-405D-A1FC-40CAFCAD190C}.Release|x86.ActiveCfg = Release|Any CPU
18451847
{442D1E25-FFD1-405D-A1FC-40CAFCAD190C}.Release|x86.Build.0 = Release|Any CPU
1848+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
1849+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
1850+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
1851+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
1852+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|ARM64.ActiveCfg = Debug|Any CPU
1853+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|ARM64.Build.0 = Debug|Any CPU
1854+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
1855+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
1856+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1857+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
1858+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
1859+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
1860+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
1861+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
1862+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
1863+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|Any CPU.Build.0 = Debug|Any CPU
1864+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|ARM.ActiveCfg = Debug|Any CPU
1865+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|ARM.Build.0 = Debug|Any CPU
1866+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|ARM64.ActiveCfg = Debug|Any CPU
1867+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|ARM64.Build.0 = Debug|Any CPU
1868+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
1869+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|iPhone.Build.0 = Debug|Any CPU
1870+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1871+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
1872+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|x64.ActiveCfg = Debug|Any CPU
1873+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|x64.Build.0 = Debug|Any CPU
1874+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|x86.ActiveCfg = Debug|Any CPU
1875+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.AppStore|x86.Build.0 = Debug|Any CPU
1876+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1877+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
1878+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|ARM.ActiveCfg = Debug|Any CPU
1879+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|ARM.Build.0 = Debug|Any CPU
1880+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|ARM64.ActiveCfg = Debug|Any CPU
1881+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|ARM64.Build.0 = Debug|Any CPU
1882+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|iPhone.ActiveCfg = Debug|Any CPU
1883+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|iPhone.Build.0 = Debug|Any CPU
1884+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
1885+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
1886+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|x64.ActiveCfg = Debug|Any CPU
1887+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|x64.Build.0 = Debug|Any CPU
1888+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|x86.ActiveCfg = Debug|Any CPU
1889+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Debug|x86.Build.0 = Debug|Any CPU
1890+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
1891+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|Any CPU.Build.0 = Release|Any CPU
1892+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|ARM.ActiveCfg = Release|Any CPU
1893+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|ARM.Build.0 = Release|Any CPU
1894+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|ARM64.ActiveCfg = Release|Any CPU
1895+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|ARM64.Build.0 = Release|Any CPU
1896+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|iPhone.ActiveCfg = Release|Any CPU
1897+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|iPhone.Build.0 = Release|Any CPU
1898+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
1899+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
1900+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|x64.ActiveCfg = Release|Any CPU
1901+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|x64.Build.0 = Release|Any CPU
1902+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|x86.ActiveCfg = Release|Any CPU
1903+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A}.Release|x86.Build.0 = Release|Any CPU
18461904
EndGlobalSection
18471905
GlobalSection(SolutionProperties) = preSolution
18481906
HideSolutionNode = FALSE
@@ -1881,6 +1939,7 @@ Global
18811939
{3A5D7EA4-5AD9-4D34-87E6-B34416CA928E} = {01380FB8-F8A7-4416-AABA-5407574B7723}
18821940
{F8D00106-0598-45E7-B92E-EF408249C02E} = {01380FB8-F8A7-4416-AABA-5407574B7723}
18831941
{442D1E25-FFD1-405D-A1FC-40CAFCAD190C} = {01380FB8-F8A7-4416-AABA-5407574B7723}
1942+
{C8DF10B0-D157-47CF-BD10-9EE1D06BEB9A} = {01380FB8-F8A7-4416-AABA-5407574B7723}
18841943
EndGlobalSection
18851944
GlobalSection(ExtensibilityGlobals) = postSolution
18861945
SolutionGuid = {3921AD86-E6C0-4436-8880-2D9EDFAD6151}

samples/MADE.Samples/MADE.Samples.Droid/MADE.Samples.Droid.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@
115115
<Project>{713ab96d-1ee2-45ca-a41e-47401edcc656}</Project>
116116
<Name>MADE.Diagnostics</Name>
117117
</ProjectReference>
118+
<ProjectReference Include="..\..\..\src\MADE.Foundation\MADE.Foundation.csproj">
119+
<Project>{c8df10b0-d157-47cf-bd10-9ee1d06beb9a}</Project>
120+
<Name>MADE.Foundation</Name>
121+
</ProjectReference>
118122
<ProjectReference Include="..\..\..\src\MADE.Networking\MADE.Networking.csproj">
119123
<Project>{aa0647a7-110f-4fb8-88f7-a902cbb240a3}</Project>
120124
<Name>MADE.Networking</Name>

samples/MADE.Samples/MADE.Samples.Shared/Features/Home/ViewModels/MainPageViewModel.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ namespace MADE.Samples.Features.Home.ViewModels
55
using System.Windows.Input;
66
using CommunityToolkit.Mvvm.Input;
77
using CommunityToolkit.Mvvm.Messaging;
8+
using Foundation.Platform;
89
using MADE.Samples.Features.Samples.Data;
910
using MADE.Samples.Features.Samples.Pages;
1011
using MADE.UI.Views.Navigation;
1112
using MADE.UI.Views.Navigation.ViewModels;
13+
using UI.ViewManagement;
1214

1315
public class MainPageViewModel : PageViewModel
1416
{
@@ -19,12 +21,14 @@ public MainPageViewModel(INavigationService navigationService, IMessenger messen
1921

2022
public ICommand NavigateToSampleCommand => new RelayCommand<Sample>(NavigateToSample);
2123

22-
public ICollection<SampleGroup> SampleGroups { get; } = new List<SampleGroup>
24+
public ICollection<SampleGroup> SampleGroups { get; } = GetSampleGroups();
25+
26+
private static ICollection<SampleGroup> GetSampleGroups()
2327
{
24-
new SampleGroup
28+
var controls = new SampleGroup
2529
{
2630
Name = "Controls",
27-
Samples = new List<Sample>
31+
Samples =
2832
{
2933
new Sample(
3034
"FilePicker",
@@ -35,23 +39,37 @@ public MainPageViewModel(INavigationService navigationService, IMessenger messen
3539
typeof(InputValidatorPage),
3640
"/Features/Samples/Assets/InputValidator/InputValidator.png")
3741
}
38-
},
39-
new SampleGroup
42+
};
43+
44+
var helpers = new SampleGroup
4045
{
4146
Name = "Helpers",
42-
Samples = new List<Sample>
47+
Samples =
4348
{
4449
new Sample(
4550
"AppDialog",
4651
typeof(AppDialogPage),
4752
"/Features/Samples/Assets/AppDialog/AppDialog.png"),
53+
}
54+
};
55+
56+
if (PlatformApiHelper.IsTypeSupported(typeof(WindowManager)))
57+
{
58+
helpers.Samples.Add(
4859
new Sample(
4960
"WindowManager",
5061
typeof(WindowManagerPage),
51-
"/Features/Samples/Assets/WindowManager/WindowManager.png")
52-
}
62+
"/Features/Samples/Assets/WindowManager/WindowManager.png"));
5363
}
54-
};
64+
65+
var list = new List<SampleGroup>
66+
{
67+
controls,
68+
helpers
69+
};
70+
71+
return list;
72+
}
5573

5674
public ICollection<Sample> Samples => SampleGroups.SelectMany(x => x.Samples).ToList();
5775

samples/MADE.Samples/MADE.Samples.Shared/Features/Samples/Data/SampleGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public class SampleGroup
66
{
77
public string Name { get; set; }
88

9-
public IEnumerable<Sample> Samples { get; set; }
9+
public ICollection<Sample> Samples { get; } = new List<Sample>();
1010
}
1111
}

samples/MADE.Samples/MADE.Samples.UWP/MADE.Samples.UWP.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@
151151
<Project>{713ab96d-1ee2-45ca-a41e-47401edcc656}</Project>
152152
<Name>MADE.Diagnostics</Name>
153153
</ProjectReference>
154+
<ProjectReference Include="..\..\..\src\MADE.Foundation\MADE.Foundation.csproj">
155+
<Project>{c8df10b0-d157-47cf-bd10-9ee1d06beb9a}</Project>
156+
<Name>MADE.Foundation</Name>
157+
</ProjectReference>
154158
<ProjectReference Include="..\..\..\src\MADE.Media.Image\MADE.Media.Image.csproj">
155159
<Project>{3038eda8-3068-45ad-99a2-36986627b880}</Project>
156160
<Name>MADE.Media.Image</Name>

samples/MADE.Samples/MADE.Samples.Wasm/MADE.Samples.Wasm.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<ProjectReference Include="..\..\..\src\MADE.Data.Converters\MADE.Data.Converters.csproj" />
5252
<ProjectReference Include="..\..\..\src\MADE.Data.Validation\MADE.Data.Validation.csproj" />
5353
<ProjectReference Include="..\..\..\src\MADE.Diagnostics\MADE.Diagnostics.csproj" />
54+
<ProjectReference Include="..\..\..\src\MADE.Foundation\MADE.Foundation.csproj" />
5455
<ProjectReference Include="..\..\..\src\MADE.Networking\MADE.Networking.csproj" />
5556
<ProjectReference Include="..\..\..\src\MADE.Runtime\MADE.Runtime.csproj" />
5657
<ProjectReference Include="..\..\..\src\MADE.Threading\MADE.Threading.csproj" />

samples/MADE.Samples/MADE.Samples.iOS/MADE.Samples.iOS.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@
177177
<Project>{713ab96d-1ee2-45ca-a41e-47401edcc656}</Project>
178178
<Name>MADE.Diagnostics</Name>
179179
</ProjectReference>
180+
<ProjectReference Include="..\..\..\src\MADE.Foundation\MADE.Foundation.csproj">
181+
<Project>{c8df10b0-d157-47cf-bd10-9ee1d06beb9a}</Project>
182+
<Name>MADE.Foundation</Name>
183+
</ProjectReference>
180184
<ProjectReference Include="..\..\..\src\MADE.Networking\MADE.Networking.csproj">
181185
<Project>{aa0647a7-110f-4fb8-88f7-a902cbb240a3}</Project>
182186
<Name>MADE.Networking</Name>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="MSBuild.Sdk.Extras">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>uap10.0.17763;MonoAndroid10.0;xamarinios10;netstandard2.0;xamarinmac20</TargetFrameworks>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<Product>MADE.NET Foundation</Product>
7+
<Description>
8+
This package includes foundational helpers for other MADE libraries such as:
9+
-
10+
</Description>
11+
<PackageTags>MADE Foundation Helpers</PackageTags>
12+
13+
</PropertyGroup>
14+
15+
</Project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace MADE.Foundation.Platform
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Reflection;
6+
7+
/// <summary>
8+
/// Defines a helper for checking platform support for APIs.
9+
/// </summary>
10+
public static class PlatformApiHelper
11+
{
12+
private static readonly object Lock = new object();
13+
14+
private static readonly Dictionary<Type, bool> CheckedTypes = new Dictionary<Type, bool>();
15+
16+
/// <summary>
17+
/// Indicates whether the specified <paramref name="type"/> is supported by the platform.
18+
/// </summary>
19+
/// <param name="type">The type to check.</param>
20+
/// <returns>True if supported; otherwise, false.</returns>
21+
public static bool IsTypeSupported(Type type)
22+
{
23+
lock (Lock)
24+
{
25+
if (!CheckedTypes.TryGetValue(type, out var result))
26+
{
27+
CheckedTypes[type] = result = IsSupported(type);
28+
}
29+
30+
return result;
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Indicates whether the specified <paramref name="methodName"/> on <paramref name="type"/> is supported by the platform.
36+
/// </summary>
37+
/// <param name="type">The type where the method should be checked.</param>
38+
/// <param name="methodName">The name of the method to check.</param>
39+
/// <returns>True if supported; otherwise, false.</returns>
40+
public static bool IsMethodSupported(Type type, string methodName)
41+
{
42+
var result = IsTypeSupported(type);
43+
if (!result)
44+
{
45+
result = IsSupported(type.GetMethod(methodName));
46+
}
47+
48+
return result;
49+
}
50+
51+
/// <summary>
52+
/// Indicates whether the specified <paramref name="propertyName"/> on <paramref name="type"/> is supported by the platform.
53+
/// </summary>
54+
/// <param name="type">The type where the property should be checked.</param>
55+
/// <param name="propertyName">The name of the property to check.</param>
56+
/// <returns>True if supported; otherwise, false.</returns>
57+
public static bool IsPropertySupported(Type type, string propertyName)
58+
{
59+
var result = IsTypeSupported(type);
60+
if (!result)
61+
{
62+
result = IsSupported(type.GetProperty(propertyName));
63+
}
64+
65+
return result;
66+
}
67+
68+
private static bool IsSupported(ICustomAttributeProvider attributeProvider)
69+
{
70+
return (attributeProvider?.GetCustomAttributes(typeof(PlatformNotSupportedAttribute), false).Length ?? -1) == 0;
71+
}
72+
}
73+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace MADE.Foundation.Platform
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// Defines an attribute that marks a component as not supported by a specific platform.
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.All, Inherited = false)]
9+
public sealed class PlatformNotSupportedAttribute : Attribute
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="PlatformNotSupportedAttribute"/> class.
13+
/// </summary>
14+
public PlatformNotSupportedAttribute()
15+
{
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)