/// <summary> /// Initializes a new instance of the <see cref="LocalizeAttributeTagHelper" /> class. /// </summary> /// <param name="localizerFactory">The localizer factory.</param> /// <param name="hostingEnvironment">The hosting environment.</param> public LocalizeAttributeTagHelper(IHtmlLocalizerFactory localizerFactory, IHostingEnvironment hostingEnvironment) { Throws.NotNull(localizerFactory, nameof(localizerFactory)); Throws.NotNull(hostingEnvironment, nameof(hostingEnvironment)); this.localizerFactory = localizerFactory; applicationName = hostingEnvironment.ApplicationName; }
/// <summary> /// Initializes a new instance of the <see cref="GenericLocalizeTagHelper" /> class. /// </summary> /// <param name="localizerFactory"> /// The localizer factory to create a <see cref="IHtmlLocalizer" /> from. /// </param> /// <param name="hostingEnvironment">The hosting environment.</param> /// <param name="options">The default options unless overridden when calling the tag helper.</param> public GenericLocalizeTagHelper(IHtmlLocalizerFactory localizerFactory, IHostingEnvironment hostingEnvironment, IOptions <LocalizeTagHelperOptions> options) { Throws.NotNull(localizerFactory, nameof(localizerFactory)); Throws.NotNull(hostingEnvironment, nameof(hostingEnvironment)); this.localizerFactory = localizerFactory; this.applicationName = hostingEnvironment.ApplicationName; if (options != null) { NewLineHandling = options.Value.NewLineHandling; TrimWhitespace = options.Value.TrimWhitespace; } else { NewLineHandling = NewLineHandling.Auto; TrimWhitespace = true; } }
public async Task <SqlDefinition> ExecuteAsync(string sqlTemplate, object model, TemplateOptions options) { Throws.NotEmpty(sqlTemplate, nameof(sqlTemplate)); Throws.NotNull(model, nameof(model)); if (options == null) { options = TemplateOptions.Default; } var modelType = model.GetType(); ValidateModel(modelType, model); var globalsType = typeof(Globals <>).MakeGenericType(modelType); var runner = pool.GetOrAdd(Tuple.Create(sqlTemplate, modelType), v => { var parser = new CSharpScriptCodeParser(sqlTemplate); var parseResult = parser.Parse(); var scriptOptions = ScriptOptions.Default.AddReferences( typeof(SqlTemplateEngine).GetTypeInfo().Assembly, modelType.GetTypeInfo().Assembly ).AddImports("Km.Toi.Template", "System", "System.Linq") .AddImports(parseResult.Imports); return(CSharpScript.Create(parseResult.Code, scriptOptions, globalsType).CreateDelegate()); }); var builder = new SqlDefinitionBuilder(options); var global = Activator.CreateInstance(globalsType, model, builder) as IGlobals; await runner(global); return(builder.Build()); }