Skip to content

Instantly share code, notes, and snippets.

Hendrik Bulens hbulens

Block or report user

Report or block hbulens

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 2015-07-24-how-to-automatically-load-navigation-properties-in-entity-framework_004.cs
internal static IQueryable<TEntity> Include<TEntity>(this IQueryable<TEntity> query, DbContext context, params string[] includes) where TEntity : class
{
// Do a safety check first
if (includes == null)
return query;
List<string> includeList = new List<string>();
if (includes.Any())
return includes
.Where(x => !string.IsNullOrEmpty(x) && !includeList.Contains(x))
View resources-to-javascript-006.cs
internal static class ResourceGroupExtensions
{
/// <summary>
/// Converts the source data to a Javascript variable
/// </summary>
/// <param name="resources">The record to convert</param>
/// <returns>A valid Javascript object</returns>
internal static string ToJavascript(this IEnumerable<ResourceGroup> resources)
{
StringBuilder sb = new StringBuilder();
View resources-to-javascript-005.cs
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Localization;
using System.Linq;
using System.Reflection;
namespace InjectJavascriptToWebApp
{
View resources-to-javascript-004.cshtml
<environment include="Development">
<resources names='new[] { "Labels" }'></resources>
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
</environment>
View resources-to-javascript-008.cs
public class ResourcesHelper
{
private readonly IStringLocalizerFactory _stringLocalizerFactory;
public ResourcesHelper(IStringLocalizerFactory stringLocalizerFactory)
{
_stringLocalizerFactory = stringLocalizerFactory;
}
public IEnumerable<LocalizedString> GetResources(string name)
View resources-to-javascript-007.cs
internal class ResourceGroup
{
public string Name { get; set; }
public IEnumerable<LocalizedString> Entries { get; set; }
}
View resources-to-javascript-001_a.cs
services.AddLocalization(options => options.ResourcesPath = "Resources");
View resources-to-javascript-001.cs
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddLocalization(options => options.ResourcesPath = "Resources");
View resources-to-javascript-002.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
View resources-to-javascript-003.cs
internal class ResourceJavaScriptService
{
/// <summary>
/// Converts the source data to a Javascript variable
/// </summary>
/// <param name="fields">The record to convert</param>
/// <returns>A valid Javascript object</returns>
public string ToJavascript(IEnumerable<ResourceGroup> fields)
{
StringBuilder sb = new StringBuilder();
You can’t perform that action at this time.