-
Notifications
You must be signed in to change notification settings - Fork 22
Yevhen Bobrov edited this page Apr 3, 2020
·
5 revisions
Helper class to simplify working with environment variables.
using static Nake.Env;
// will set environment variable Log to value 1
// on the process level
Var["Log"] = 1;
// will print environment variable Log
// defined on the process level.
// Might return 'null' if
// such variable is not defined
Console.WriteLine(Var["Log"]);
// Checks whether environment variable Log
// is defined on the process level
Console.WriteLine(Var.Defined("Log"));
// You can also use null-coalescing operator
// to provide default value if variable is not defined
// (if variable is not defined indexer will return null)
Console.WriteLine(Var["Log"] ?? 1);
// will print out all environment variable pairs
// which are defined on the process level
foreach (var variable in Var.All())
Console.WriteLine(variable);
For working with environment variables in different than 'Process' scope, just use appropriate nested properties, which have the same api:
Var.User["Log"] = 1;
Var.Machine["Log"] = 1;