Skip to content

Commit

Permalink
Merge pull request #9 from egvijayanand/working
Browse files Browse the repository at this point in the history
Added extension methods for BlazorWebView
  • Loading branch information
egvijayanand authored Nov 17, 2021
2 parents d380c09 + 7211e69 commit b28707d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/MauiBlazorApp/MauiBlazorApp/BlazorPage.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/MauiBlazorApp/MauiBlazorApp/Extensions/BlazorExtensions.cs
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;
}
}
}

0 comments on commit b28707d

Please sign in to comment.