using System; using System.Collections.Generic; namespace NucuCar.Domain.Utilities { /// /// ConnectionStringParser is an utility service to parse and validate connection strings. /// public static class ConnectionStringParser { /// /// Parse parses and validates a provided connection string. /// /// The connection string to parse /// A dictionary object containing the values of the connection string. /// public static Dictionary Parse(string connectionString) { if (connectionString.Equals(string.Empty)) { throw new ArgumentException("ConnectionString can't be empty!"); } var items = connectionString.Split(";"); var parsedConnectionString = new Dictionary(); foreach (var item in items) { var keyValue = item.Split("="); if (keyValue.Length != 2) { throw new ArgumentException( $"Invalid argument for connection string, expected KEY=VALUE got {item}"); } parsedConnectionString.Add(keyValue[0], keyValue[1]); } return parsedConnectionString; } } }