public static void SetName(this NamedMetadataObject obj, string newName, Culture culture = null) { if (culture != null) { culture.ObjectTranslations.SetTranslation(obj, TranslatedProperty.Caption, newName); } else { if (obj.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)) { obj.Name = newName; return; } // Automatically apply name change to translations (but only if the translation is identical to the old name): var cultures = obj.Model?.Cultures; if (cultures != null && obj.IsTranslatable()) { foreach (var c in cultures) { var translatedName = obj.GetName(c); if (!string.IsNullOrEmpty(translatedName) && translatedName.Equals(obj.Name, StringComparison.InvariantCultureIgnoreCase)) { obj.SetName(newName, c); } } } if (!obj.IsRemoved) { obj.Name = newName; } } }
public static void SetName(this NamedMetadataObject obj, string newName, Culture culture = null) { if (culture != null) { culture.ObjectTranslations.SetTranslation(obj, TranslatedProperty.Caption, newName); } else { if (obj.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)) { obj.Name = newName; return; } if (obj is Measure) { var measure = obj as Measure; // Do not allow multiple measures with the same name: if (measure.Model.Tables.Any(t => t.Measures.Any(m => m != obj && m.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))) { throw new ArgumentException(string.Format(Messages.DuplicateMeasureName, newName)); } // Do not allow a measure with the same name as a column in the table: if (measure.Table.Columns.Any(c => c.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))) { throw new ArgumentException(string.Format(Messages.DuplicateColumnName, newName)); } } else if (obj is Column) { var column = obj as Column; // Do not allow a column with the same name as a measure in the table: if (column.Table.Measures.Any(m => m.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))) { throw new ArgumentException(string.Format(Messages.DuplicateMeasureName, newName)); } // Do not allow a column with the same name as another column in the table: if (column.Table.Columns.Any(c => c != obj && c.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))) { throw new ArgumentException(string.Format(Messages.DuplicateColumnName, newName)); } } // Automatically apply name change to translations (but only if the translation is identical to the old name): var cultures = obj.Model?.Cultures; if (cultures != null && obj.IsTranslatable()) { foreach (var c in cultures) { var translatedName = obj.GetName(c); if (!string.IsNullOrEmpty(translatedName) && translatedName.Equals(obj.Name, StringComparison.InvariantCultureIgnoreCase)) { obj.SetName(newName, c); } } } if (!obj.IsRemoved) { obj.Name = newName; } } }