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