-
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.
Merge pull request #16 from fortedigital/feature/support-framework-4_8
Added support for .NET Framework 4 8
- Loading branch information
Showing
13 changed files
with
280 additions
and
60 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
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 |
---|---|---|
@@ -1,24 +1,81 @@ | ||
using System.Threading.Tasks; | ||
using Forte.React.AspNetCore.React; | ||
using Forte.React.AspNetCore.React; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
#if NET48 | ||
using System.Web.Mvc; | ||
using System.Web; | ||
#endif | ||
|
||
#if NET6_0_OR_GREATER | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Html; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Microsoft.Extensions.DependencyInjection; | ||
#endif | ||
|
||
namespace Forte.React.AspNetCore; | ||
|
||
public static class HtmlHelperExtensions | ||
{ | ||
#if NET48 | ||
public static IHtmlString React<T>(this HtmlHelper _, string componentName, T props) | ||
{ | ||
var reactService = DependencyResolver.Current.GetService<IReactService>(); | ||
var renderedComponent = reactService.RenderToStringAsync(componentName, props).GetAwaiter().GetResult(); | ||
|
||
return new HtmlString(renderedComponent); | ||
} | ||
|
||
public static IHtmlString React<TComponent>(this HtmlHelper _, TComponent component) where TComponent : IReactComponent | ||
{ | ||
var reactService = DependencyResolver.Current.GetService<IReactService>(); | ||
var renderedComponent = reactService.RenderToStringAsync(component.Path, null, component.ClientOnly).GetAwaiter().GetResult(); | ||
|
||
return new HtmlString(renderedComponent); | ||
} | ||
|
||
public static IHtmlString React<TComponent, TProps>(this HtmlHelper _, TComponent component) where TComponent : IReactComponent<TProps> where TProps : IReactComponentProps | ||
{ | ||
var reactService = DependencyResolver.Current.GetService<IReactService>(); | ||
var renderedComponent = reactService.RenderToStringAsync(component.Path, component.Props, component.ClientOnly).GetAwaiter().GetResult(); | ||
|
||
return new HtmlString(renderedComponent); | ||
} | ||
|
||
public static IHtmlString InitJavascript(this HtmlHelper _) | ||
{ | ||
var reactService = DependencyResolver.Current.GetService<IReactService>(); | ||
|
||
return new HtmlString(reactService.GetInitJavascript()); | ||
} | ||
#endif | ||
|
||
#if NET6_0_OR_GREATER | ||
public static async Task<IHtmlContent> ReactAsync<T>(this IHtmlHelper htmlHelper, string componentName, T props) | ||
{ | ||
var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService<IReactService>(); | ||
|
||
return new HtmlString(await reactService.RenderToStringAsync(componentName, props)); | ||
} | ||
|
||
public static async Task<IHtmlContent> ReactAsync<TComponent>(this IHtmlHelper htmlHelper, TComponent component) where TComponent : IReactComponent | ||
{ | ||
var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService<IReactService>(); | ||
|
||
return new HtmlString(await reactService.RenderToStringAsync(component.Path, null, component.ClientOnly)); | ||
} | ||
|
||
public static async Task<IHtmlContent> ReactAsync<TComponent, TProps>(this IHtmlHelper htmlHelper, TComponent component) where TComponent : IReactComponent<TProps> where TProps : IReactComponentProps | ||
{ | ||
var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService<IReactService>(); | ||
|
||
return new HtmlString(await reactService.RenderToStringAsync(component.Path, component.Props, component.ClientOnly)); | ||
} | ||
|
||
public static IHtmlContent InitJavascript(this IHtmlHelper htmlHelper) | ||
{ | ||
var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService<IReactService>(); | ||
|
||
return new HtmlString(reactService.GetInitJavascript()); | ||
} | ||
#endif | ||
} |
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,12 @@ | ||
namespace Forte.React.AspNetCore.React; | ||
|
||
public interface IReactComponent<out TProps> : IReactComponent where TProps : IReactComponentProps | ||
{ | ||
TProps Props { get; } | ||
} | ||
|
||
public interface IReactComponent | ||
{ | ||
string Path { get; } | ||
bool ClientOnly { get; } | ||
} |
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,5 @@ | ||
namespace Forte.React.AspNetCore.React; | ||
|
||
public interface IReactComponentProps | ||
{ | ||
} |
Oops, something went wrong.