Last active
August 29, 2015 14:18
-
-
Save tanaka-takayoshi/948253c5dcc26e4c2e00 to your computer and use it in GitHub Desktop.
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
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