private HashSet <string> GetNonExistingMappingFields(IReadOnlyMap <string, string> fieldsMapping) { var nonExistingFields = new HashSet <string>(); string mappedFieldName; foreach (var fieldName in base.GetFieldNames()) { if (!fieldsMapping.TryGetKey(fieldName, out mappedFieldName)) { // If nothing maps into current field - ignore continue; } // There is a mapping that results into already existing field, preserve source field name nonExistingFields.Add(mappedFieldName); } // All preserved source field names should be ignored (should not belong to data item), otherwise we have a conflict foreach (var fieldName in base.GetFieldNames()) { if (nonExistingFields.Contains(fieldName) && // this is not a check, just get target field name for the exception message fieldsMapping.TryGetValue(fieldName, out mappedFieldName)) { throw Errors.DataItemAlreadyContainsField(mappedFieldName); } } return(nonExistingFields); }
public override IEnumerable <string> GetFieldNames() { string newFieldName; foreach (var fieldName in base.GetFieldNames()) { yield return(fieldsMapping.TryGetValue(fieldName, out newFieldName) ? newFieldName : fieldName); } }
private HashSet<string> GetNonExistingMappingFields(IReadOnlyMap<string, string> fieldsMapping) { var nonExistingFields = new HashSet<string>(); string mappedFieldName; foreach (var fieldName in base.GetFieldNames()) { if (!fieldsMapping.TryGetKey(fieldName, out mappedFieldName)) // If nothing maps into current field - ignore continue; // There is a mapping that results into already existing field, preserve source field name nonExistingFields.Add(mappedFieldName); } // All preserved source field names should be ignored (should not belong to data item), otherwise we have a conflict foreach (var fieldName in base.GetFieldNames()) if (nonExistingFields.Contains(fieldName) && // this is not a check, just get target field name for the exception message fieldsMapping.TryGetValue(fieldName, out mappedFieldName)) throw Errors.DataItemAlreadyContainsField(mappedFieldName); return nonExistingFields; }
public static Boolean TryGetValue <TKey, TValue>(this IReadOnlyMap <TKey, TValue> map, TValue key, out TKey result) { return(map.TryGetValue(key, out result)); }