/// <summary> /// Gets the ID of an existing firewall. /// </summary> /// <param name="client">The FirewallClient to use to obtain the firewall /// ID.</param> /// <param name="name">The name of the firewall to obtain the ID for.</param> /// <returns>The firewall ID if it exists. Returns an empty string if no firewall /// exists with the given <paramref name="name"/>.</returns> public static string GetExistingFirewall(this FirewallClient client, string name) { var existingFirewalls = client.GetFirewallGroups(); bool Predicate(KeyValuePair <string, FirewallGroup> existingFirewall) => existingFirewall.Value.description == name; if (existingFirewalls.FirewallGroups == null || !existingFirewalls.FirewallGroups.Exists(Predicate)) { return(""); } var(existingFirewallGroupId, _) = existingFirewalls.FirewallGroups.Single(Predicate); return(existingFirewallGroupId); }