private bool IsEnabled() { if (localAttr == null) { return(false); } if (localRowInstance != null) { return(true); } localRowInstance = (ILocalizationRow)Activator.CreateInstance(localAttr.LocalizationRow); rowPrefixLength = PrefixHelper.DeterminePrefixLength(BasedOnRow.EnumerateTableFields(), x => x.Name); localRowPrefixLength = PrefixHelper.DeterminePrefixLength(localRowInstance.EnumerateTableFields(), x => x.Name); mappedIdField = localRowInstance.FindField(localAttr.MappedIdField ?? BasedOnRow.IdField.Name); if (mappedIdField is null) { throw new InvalidOperationException(string.Format("Can't locate localization table mapped ID field for {0}!", localRowInstance.Table)); } return(true); }
internal static Field GetLocalizationMatch(Field field, ILocalizationRow localRowInstance, int localRowPrefixLength, int rowPrefixLength) { if (!field.IsTableField()) { return(null); } var name = field.Name[rowPrefixLength..];
public bool ActivateFor(IRow row) { attr = row.GetType().GetCustomAttribute <LocalizationRowAttribute>(); if (attr == null) { return(false); } localRowType = attr.LocalizationRow; if (!typeof(ILocalizationRow).IsAssignableFrom(localRowType)) { throw new ArgumentException(string.Format( "Row type '{0}' has a LocalizationRowAttribute, " + "but its localization row type ('{1}') doesn't implement ILocalizationRow interface!", row.GetType().FullName, localRowType.FullName)); } if (!typeof(IIdRow).IsAssignableFrom(localRowType)) { throw new ArgumentException(string.Format( "Row type '{0}' has a LocalizationRowAttribute, " + "but its localization row type ('{1}') doesn't implement IIdRow interface!", row.GetType().FullName, localRowType.FullName)); } if (!(row is IIdRow)) { throw new ArgumentException(string.Format( "Row type '{0}' has a LocalizationRowAttribute, " + "but row type itself doesn't implement IIdRow interface!", row.GetType().FullName)); } var rowType = row.GetType(); rowFactory = () => (IIdRow)Activator.CreateInstance(rowType); localRowFactory = () => (ILocalizationRow)Activator.CreateInstance(localRowType); var localRow = localRowFactory(); localRowInstance = localRow; rowPrefixLength = PrefixHelper.DeterminePrefixLength(row.EnumerateTableFields(), x => x.Name); localRowPrefixLength = PrefixHelper.DeterminePrefixLength(localRow.EnumerateTableFields(), x => x.Name); localRowIdField = localRow.IdField; cultureIdField = localRow.CultureIdField; var foreignKeyFieldName = attr.MappedIdField ?? row.IdField.PropertyName; foreignKeyField = localRow.FindFieldByPropertyName(foreignKeyFieldName) ?? localRow.FindField(foreignKeyFieldName); if (foreignKeyField is null) { throw new ArgumentException(string.Format( "Row type '{0}' has a LocalizationRowAttribute, " + "but its localization row type ('{1}') doesn't have a field with name '{2}'!", row.GetType().FullName, localRowType.FullName, foreignKeyFieldName)); } var dictionaryType = typeof(Dictionary <,>).MakeGenericType(typeof(string), row.GetType()); dictionaryFactory = () => (IDictionary)Activator.CreateInstance(dictionaryType); foreignKeyCriteria = new Criteria(foreignKeyField.PropertyName ?? foreignKeyField.Name); return(true); }