/// <summary> /// Constructs the proper SSDL identifier for a given XML element name. /// </summary> /// <param name="elementName">The <code>name</code> attribute on the XML element.</param> /// <returns>The proper SSDL identifier based on <paramref name="elementName"/>.</returns> private static IEnumerable <XName> Names(string elementName) { DebugCheck.NotNullOrWhiteSpace(elementName); return(new List <XName> { _ssdlNamespaceV3 + elementName, _ssdlNamespaceV2 + elementName }); }
/// <summary> /// Formats a database table name to a <code>Schema.TableName</code> pattern. /// Schema name is optional; if no schema is specified then the /// default schema from the <see cref="System.Data.SqlClient.SqlConnection"/> is assumed. /// </summary> /// <param name="tableName">The name of the table, standardized or not.</param> /// <returns>A standardized database table name.</returns> private string GetStandardizedTableName(string tableName) { DebugCheck.NotNullOrWhiteSpace(tableName); var databaseName = DatabaseName.Parse(tableName); if (!string.IsNullOrWhiteSpace(databaseName.Schema)) { return(tableName); } return(new DatabaseName(tableName, DefaultSchema).ToString()); }
/// <summary> /// Extracts possibly the table name and schema name /// from a <see cref="string"/>. /// </summary> /// <param name="name">A <see cref="string"/> that possibly contains a table name and schema name.</param> /// <returns>A <see cref="org.christchapelbc.Utility.Migrations.FluentMigration.FluentDbMigration.DatabaseName"/> object with properties extracted from the input.</returns> public static DatabaseName Parse(string name) { DebugCheck.NotNullOrWhiteSpace(name); string namePartRegex = @"(?:(?:\[(?<part{0}>(?:(?:\]\])|[^\]])+)\])|(?<part{0}>[^\.\[\]]+))"; Regex namePartExtractor = new Regex ( string.Format ( CultureInfo.InvariantCulture, @"^{0}(?:\.{1})?$", string.Format ( CultureInfo.InvariantCulture, namePartRegex, 1 ), string.Format ( CultureInfo.InvariantCulture, namePartRegex, 2 ) ), RegexOptions.Compiled ); Match match = namePartExtractor.Match(name.Trim()); if (!match.Success) { throw new ArgumentException(string.Format("{0} is not a valid database table name.", name)); } string match1 = match.Groups["part1"].Value.Replace("]]", "]"); string match2 = match.Groups["part2"].Value.Replace("]]", "]"); return(!string.IsNullOrWhiteSpace(match2) ? new DatabaseName(match2, match1) : new DatabaseName(match1)); }