-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement .NET 6 features for templates. (#3018)
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
- Loading branch information
1 parent
42af2a7
commit e9eb388
Showing
30 changed files
with
271 additions
and
308 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,17 +1,11 @@ | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; | ||
using Application = Microsoft.Maui.Controls.Application; | ||
namespace MauiApp._1; | ||
|
||
namespace MauiApp._1 | ||
public partial class App : Application | ||
{ | ||
public partial class App : Application | ||
public App() | ||
{ | ||
public App() | ||
{ | ||
InitializeComponent(); | ||
InitializeComponent(); | ||
|
||
MainPage = new MainPage(); | ||
} | ||
MainPage = new MainPage(); | ||
} | ||
} |
15 changes: 6 additions & 9 deletions
15
src/Templates/src/templates/maui-blazor/Data/WeatherForecast.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 |
---|---|---|
@@ -1,15 +1,12 @@ | ||
using System; | ||
namespace MauiApp._1.Data; | ||
|
||
namespace MauiApp._1.Data | ||
public class WeatherForecast | ||
{ | ||
public class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
public DateTime Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
public int TemperatureC { get; set; } | ||
|
||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
|
||
public string Summary { get; set; } | ||
} | ||
public string Summary { get; set; } | ||
} |
30 changes: 13 additions & 17 deletions
30
src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.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 |
---|---|---|
@@ -1,24 +1,20 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
namespace MauiApp._1.Data; | ||
|
||
namespace MauiApp._1.Data | ||
public class WeatherForecastService | ||
{ | ||
public class WeatherForecastService | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate) | ||
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate) | ||
{ | ||
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
{ | ||
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
{ | ||
Date = startDate.AddDays(index), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
}).ToArray()); | ||
} | ||
Date = startDate.AddDays(index), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
}).ToArray()); | ||
} | ||
} | ||
|
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,14 @@ | ||
global using Microsoft.Extensions.DependencyInjection; | ||
global using Microsoft.Maui; | ||
global using Microsoft.Maui.Controls; | ||
global using Microsoft.Maui.Controls.Hosting; | ||
global using Microsoft.Maui.Controls.Xaml; | ||
global using Microsoft.Maui.Essentials; | ||
global using Microsoft.Maui.Hosting; | ||
global using System; | ||
global using System.Collections.Generic; | ||
global using System.IO; | ||
global using System.Linq; | ||
global using System.Net.Http; | ||
global using System.Threading; | ||
global using System.Threading.Tasks; |
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,13 +1,9 @@ | ||
using System; | ||
using Microsoft.Maui.Controls; | ||
namespace MauiApp._1; | ||
|
||
namespace MauiApp._1 | ||
public partial class MainPage : ContentPage | ||
{ | ||
public partial class MainPage : ContentPage | ||
public MainPage() | ||
{ | ||
public MainPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
InitializeComponent(); | ||
} | ||
} |
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,30 +1,24 @@ | ||
using Microsoft.AspNetCore.Components.WebView.Maui; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Hosting; | ||
using Microsoft.Maui.Controls.Compatibility; | ||
using Microsoft.Maui.Controls.Hosting; | ||
using MauiApp._1.Data; | ||
|
||
namespace MauiApp._1 | ||
namespace MauiApp._1; | ||
|
||
public static class MauiProgram | ||
{ | ||
public static class MauiProgram | ||
public static MauiApp CreateMauiApp() | ||
{ | ||
public static MauiApp CreateMauiApp() | ||
{ | ||
var builder = MauiApp.CreateBuilder(); | ||
builder | ||
.RegisterBlazorMauiWebView() | ||
.UseMauiApp<App>() | ||
.ConfigureFonts(fonts => | ||
{ | ||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); | ||
}); | ||
var builder = MauiApp.CreateBuilder(); | ||
builder | ||
.RegisterBlazorMauiWebView() | ||
.UseMauiApp<App>() | ||
.ConfigureFonts(fonts => | ||
{ | ||
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); | ||
}); | ||
|
||
builder.Services.AddBlazorWebView(); | ||
builder.Services.AddSingleton<WeatherForecastService>(); | ||
builder.Services.AddBlazorWebView(); | ||
builder.Services.AddSingleton<WeatherForecastService>(); | ||
|
||
return builder.Build(); | ||
} | ||
return builder.Build(); | ||
} | ||
} | ||
} |
21 changes: 16 additions & 5 deletions
21
src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.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 |
---|---|---|
@@ -1,11 +1,22 @@ | ||
using Android.App; | ||
using Android.Content.PM; | ||
using Microsoft.Maui; | ||
using Android.OS; | ||
|
||
namespace MauiApp._1 | ||
namespace MauiApp._1; | ||
|
||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] | ||
public class MainActivity : MauiAppCompatActivity | ||
{ | ||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] | ||
public class MainActivity : MauiAppCompatActivity | ||
protected override void OnCreate(Bundle savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
Platform.Init(this, savedInstanceState); | ||
} | ||
|
||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) | ||
{ | ||
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
base.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||
} | ||
} | ||
} |
24 changes: 10 additions & 14 deletions
24
src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.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 |
---|---|---|
@@ -1,19 +1,15 @@ | ||
using System; | ||
using Android.App; | ||
using Android.App; | ||
using Android.Runtime; | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Hosting; | ||
|
||
namespace MauiApp._1 | ||
namespace MauiApp._1; | ||
|
||
[Application] | ||
public class MainApplication : MauiApplication | ||
{ | ||
[Application] | ||
public class MainApplication : MauiApplication | ||
public MainApplication(IntPtr handle, JniHandleOwnership ownership) | ||
: base(handle, ownership) | ||
{ | ||
public MainApplication(IntPtr handle, JniHandleOwnership ownership) | ||
: base(handle, ownership) | ||
{ | ||
} | ||
|
||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} | ||
} | ||
|
||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} |
15 changes: 6 additions & 9 deletions
15
src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
using Foundation; | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Hosting; | ||
|
||
namespace MauiApp._1 | ||
namespace MauiApp._1; | ||
|
||
[Register("AppDelegate")] | ||
public class AppDelegate : MauiUIApplicationDelegate | ||
{ | ||
[Register("AppDelegate")] | ||
public class AppDelegate : MauiUIApplicationDelegate | ||
{ | ||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} | ||
} | ||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} |
17 changes: 8 additions & 9 deletions
17
src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using UIKit; | ||
|
||
namespace MauiApp._1 | ||
namespace MauiApp._1; | ||
|
||
public class Program | ||
{ | ||
public class Program | ||
// This is the main entry point of the application. | ||
static void Main(string[] args) | ||
{ | ||
// This is the main entry point of the application. | ||
static void Main(string[] args) | ||
{ | ||
// if you want to use a different Application Delegate class from "AppDelegate" | ||
// you can specify it here. | ||
UIApplication.Main(args, null, typeof(AppDelegate)); | ||
} | ||
// if you want to use a different Application Delegate class from "AppDelegate" | ||
// you can specify it here. | ||
UIApplication.Main(args, null, typeof(AppDelegate)); | ||
} | ||
} |
39 changes: 18 additions & 21 deletions
39
src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.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 |
---|---|---|
@@ -1,34 +1,31 @@ | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Hosting; | ||
using Microsoft.UI.Xaml; | ||
using Windows.ApplicationModel; | ||
using Microsoft.UI.Xaml; | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
namespace MauiApp._1.WinUI | ||
namespace MauiApp._1.WinUI; | ||
|
||
/// <summary> | ||
/// Provides application-specific behavior to supplement the default Application class. | ||
/// </summary> | ||
public partial class App : MauiWinUIApplication | ||
{ | ||
/// <summary> | ||
/// Provides application-specific behavior to supplement the default Application class. | ||
/// Initializes the singleton application object. This is the first line of authored code | ||
/// executed, and as such is the logical equivalent of main() or WinMain(). | ||
/// </summary> | ||
public partial class App : MauiWinUIApplication | ||
public App() | ||
{ | ||
/// <summary> | ||
/// Initializes the singleton application object. This is the first line of authored code | ||
/// executed, and as such is the logical equivalent of main() or WinMain(). | ||
/// </summary> | ||
public App() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
this.InitializeComponent(); | ||
} | ||
|
||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
|
||
protected override void OnLaunched(LaunchActivatedEventArgs args) | ||
{ | ||
base.OnLaunched(args); | ||
protected override void OnLaunched(LaunchActivatedEventArgs args) | ||
{ | ||
base.OnLaunched(args); | ||
|
||
Microsoft.Maui.Essentials.Platform.OnLaunched(args); | ||
} | ||
Platform.OnLaunched(args); | ||
} | ||
} | ||
|
15 changes: 6 additions & 9 deletions
15
src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
using Foundation; | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Hosting; | ||
|
||
namespace MauiApp._1 | ||
namespace MauiApp._1; | ||
|
||
[Register("AppDelegate")] | ||
public class AppDelegate : MauiUIApplicationDelegate | ||
{ | ||
[Register("AppDelegate")] | ||
public class AppDelegate : MauiUIApplicationDelegate | ||
{ | ||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} | ||
} | ||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} |
19 changes: 9 additions & 10 deletions
19
src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using UIKit; | ||
|
||
namespace MauiApp._1 | ||
namespace MauiApp._1; | ||
|
||
public class Program | ||
{ | ||
public class Program | ||
// This is the main entry point of the application. | ||
static void Main(string[] args) | ||
{ | ||
// This is the main entry point of the application. | ||
static void Main(string[] args) | ||
{ | ||
// if you want to use a different Application Delegate class from "AppDelegate" | ||
// you can specify it here. | ||
UIApplication.Main(args, null, typeof(AppDelegate)); | ||
} | ||
// if you want to use a different Application Delegate class from "AppDelegate" | ||
// you can specify it here. | ||
UIApplication.Main(args, null, typeof(AppDelegate)); | ||
} | ||
} | ||
} |
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,9 +1,6 @@ | ||
using System; | ||
namespace MauiLib1; | ||
|
||
namespace MauiLib1 | ||
// All the code in this file is included in all platforms. | ||
public class Class1 | ||
{ | ||
// All the code in this file is included in all platforms. | ||
public class Class1 | ||
{ | ||
} | ||
} | ||
} |
11 changes: 4 additions & 7 deletions
11
src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
using System; | ||
namespace MauiLib1; | ||
|
||
namespace MauiLib1 | ||
// All the code in this file is only included on Android. | ||
public class PlatformClass1 | ||
{ | ||
// All the code in this file is only included on Android. | ||
public class PlatformClass1 | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.