#region License // Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved. // This source code is made available under the terms of the GNU Lesser General Public License v3.0 // https://github.com/paulkohler/minisqlquery/blob/master/LICENSE #endregion using System; using System.IO; using System.Xml.Serialization; namespace MiniSqlQuery.Core { /// /// Provides a defition of database connection by provider and name. /// [Serializable] public class DbConnectionDefinition { /// /// A default connection, an MSSQL db on localhost connecting to the "master" database using integrated authentication. /// [XmlIgnore] public static readonly DbConnectionDefinition Default; /// /// Initializes static members of the class. /// static DbConnectionDefinition() { Default = new DbConnectionDefinition { Name = "Default - MSSQL Master@localhost", ProviderName = "System.Data.SqlClient", ConnectionString = @"Server=.; Database=Master; Integrated Security=SSPI" }; } /// /// Gets or sets a comment in relation to this connection, e.g. "development..." /// /// A comment. [XmlElement(IsNullable = true)] public string Comment { get; set; } /// /// Gets or sets the connection string. /// /// The connection string. [XmlElement(IsNullable = false)] public string ConnectionString { get; set; } /// /// Gets or sets the name. /// /// The name of the definition. [XmlElement(IsNullable = false)] public string Name { get; set; } /// /// Gets or sets the name of the provider. /// /// The name of the provider. [XmlElement(IsNullable = false)] public string ProviderName { get; set; } /// /// Converts the definition from an XML string. /// /// The XML to hydrate from. /// A instance. public static DbConnectionDefinition FromXml(string xml) { using (var sr = new StringReader(xml)) { var serializer = new XmlSerializer(typeof(DbConnectionDefinition)); return (DbConnectionDefinition)serializer.Deserialize(sr); } } /// /// Returns a that represents the current . /// /// A that represents the current . public override string ToString() { return Name ?? GetType().FullName; } /// /// Serialize the object to XML. /// /// An XML string. public string ToXml() { return Utility.ToXml(this); } } }