-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from egvijayanand/working
Added extension methods for BlazorWebView
- Loading branch information
Showing
2 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/MauiBlazorApp/MauiBlazorApp/Extensions/BlazorExtensions.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,44 @@ | ||
using Microsoft.AspNetCore.Components.WebView.Maui; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MauiBlazorApp.Extensions | ||
{ | ||
public static class BlazorExtensions | ||
{ | ||
public static TBlazorWebView HostPage<TBlazorWebView>(this TBlazorWebView blazorWV, string hostPage) | ||
where TBlazorWebView : BlazorWebView | ||
{ | ||
blazorWV.HostPage = hostPage; | ||
return blazorWV; | ||
} | ||
|
||
public static TRootComponent ComponentType<TRootComponent>(this TRootComponent component, Type type) | ||
where TRootComponent : RootComponent | ||
{ | ||
component.ComponentType = type; | ||
return component; | ||
} | ||
|
||
public static TRootComponent Selector<TRootComponent>(this TRootComponent component, string selector) | ||
where TRootComponent : RootComponent | ||
{ | ||
component.Selector = selector; | ||
return component; | ||
} | ||
|
||
public static TRootComponent Parameters<TRootComponent>(this TRootComponent component, params (string key, object? value)[] parameters) | ||
where TRootComponent : RootComponent | ||
{ | ||
var dict = new Dictionary<string, object?>(); | ||
|
||
foreach (var (key, value) in parameters) | ||
{ | ||
dict.Add(key, value); | ||
} | ||
|
||
component.Parameters = dict; | ||
return component; | ||
} | ||
} | ||
} |