public string GetScriptPath(PluginEnvironment environment) { if (Environments.HasFlag(environment)) { string file = environment.GetScriptFile(); return(file != null?Path.Combine(pathRoot, file) : string.Empty); } else { return(string.Empty); } }
// (note: Microsoft already as a similar one: Microsoft.AspNetCore.Hosting.HostingEnvironmentExtensions) /// <summary> /// Returns true if any of the given environment flags matches the current environment setting in /// '<seealso cref="IHostingEnvironment"/>.EnvironmentName' (usually set by passing in an argument to the web /// application, or by setting the 'ASPNETCORE_ENVIRONMENT' environment variable). /// <para>Note that the value 'Environments.Any' (0) will match all environments.</para> /// <para>This method requires that text matching the environment names in the enum type are used to set the hosting /// environment names.</para> /// </summary> /// <param name="env"> The IHostingEnvironment to act on. </param> /// <param name="environment"> /// Environment flags to test against. If any match, or if 'environment' is 0, 'true' is returned. /// <para>Flags are used so that content rendering can be targeted to multiple environments.</para> /// </param> /// <param name="ignoreCase"> /// (Optional) If true (default) case is ignored when comparing against the 'IHostingEnvironment.EnvironmentName' value. /// </param> /// <returns> True if environment, false if not. </returns> public static bool IsEnvironment(this IHostingEnvironment env, Environments environment, bool ignoreCase = true) { if (environment == Environments.Any) { return(true); } if (env != null) { if (environment.HasFlag(Environments.Production)) { return(env.IsEnvironment(nameof(Environments.Production), ignoreCase)); } if (environment.HasFlag(Environments.Staging)) { return(env.IsEnvironment(nameof(Environments.Staging), ignoreCase)); } if (environment.HasFlag(Environments.Q2)) { return(env.IsEnvironment(nameof(Environments.Q2), ignoreCase)); } if (environment.HasFlag(Environments.QA)) { return(env.IsEnvironment(nameof(Environments.QA), ignoreCase)); } if (environment.HasFlag(Environments.Testing)) { return(env.IsEnvironment(nameof(Environments.Testing), ignoreCase)); } if (environment.HasFlag(Environments.Development)) { return(env.IsEnvironment(nameof(Environments.Development), ignoreCase)); } if (environment.HasFlag(Environments.Sandbox)) { return(env.IsEnvironment(nameof(Environments.Sandbox), ignoreCase)); } } return(false); }