Skip to content

Instantly share code, notes, and snippets.

@tanaka-takayoshi
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanaka-takayoshi/948253c5dcc26e4c2e00 to your computer and use it in GitHub Desktop.
Save tanaka-takayoshi/948253c5dcc26e4c2e00 to your computer and use it in GitHub Desktop.
public class AppSettings
{
public string Path { get; }
private readonly XElement[] settings;
public AppSettings(string path)
{
Path = path;
var document = XElement.Load(path);
settings = document.Descendants("appSettings").Descendants("add").ToArray();
}
public string this[string index]
{
get
{
return settings.FirstOrDefault(e => e.Attribute("key").Value == index)?.Attribute("value")?.Value;
}
}
}
//usage
[Cmdlet("Invoke", "Sample")]
public class SettingSampleCmdlet : PSCmdlet
{
[Parameter(Position = 1)]
[ValidateNotNullOrEmpty]
public string SettingPath { get; set; }
protected override void ProcessRecord()
{
var setting = new AppSettings(SettingPath);
var apiKey = setting["apikey"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment