Created
March 19, 2016 11:16
-
-
Save angularsen/30de1e62966f68cd9695 to your computer and use it in GitHub Desktop.
Get web/app.config setting and expand environment variables when developing locally
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
using System; | |
using System.Collections.Specialized; | |
using JetBrains.Annotations; | |
namespace MyExtensions | |
{ | |
public static class NameValueCollectionExtensions | |
{ | |
[CanBeNull] | |
public static string GetWithEnv([NotNull] this NameValueCollection nvc, [NotNull] string name) | |
{ | |
if (nvc == null) throw new ArgumentNullException(nameof(nvc)); | |
if (name == null) throw new ArgumentNullException(nameof(name)); | |
string value = nvc.Get(name); | |
if (value != null) | |
value = Environment.ExpandEnvironmentVariables(value); | |
return value; | |
} | |
} | |
} |
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
using System; | |
namespace InitialForce.LicenseService.Extensions | |
{ | |
public static class StringExtensions | |
{ | |
public static string ExpandEnv(this string s) | |
{ | |
return s == null ? null : Environment.ExpandEnvironmentVariables(s); | |
} | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<appSettings> | |
<add key="SomeApiUserName" value="%myapp_someapi_username%" /> | |
<add key="SomeApiPassword" value="%myapp_someapi_password%" /> | |
</appsettings> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment