public bool Read() { bool hasData = _reader.Read(); if (hasData) { _current = new ThingT(); FieldDictionary fields = new FieldDictionary(_reader); fields.ThingTranslations = _thingTranslations; _current.ApplyValues(fields); } return(hasData); }
/// <summary> /// /// </summary> /// <param name="fields"></param> public abstract void ApplyValues(FieldDictionary fields);
public ThingT GetThing <ThingT>(params FieldTranslation[] fieldNames) where ThingT : Thing, new() { ThingT thing = null; if (ThingTranslations != null) { string[] sourceFieldNames = new string[fieldNames.Length]; for (int i = 0; i < fieldNames.Length; i++) { sourceFieldNames[i] = fieldNames[i].SourceName; } ThingTranslation translation; if (ThingTranslations.TryGetValue(new FieldKey(sourceFieldNames), out translation)) { thing = (ThingT)translation.TranslationHandler(this); } } if (thing != null) { return(thing); } FieldDictionary fields = null; for (int i = 0; i < fieldNames.Length; i++) { // Try to get the value object o = null; this.TryGetValue(fieldNames[i].SourceName, out o); // Null of failed to retrieve - skip if (o == null) { continue; } // Init the dic if it hasn't been done yet if (fields == null) { fields = new FieldDictionary(); } // Apply the value fields[fieldNames[i].TargetName] = o; } if (fields == null) { return(null); } fields.ThingTranslations = this.ThingTranslations; // Create the new thing and apply its values thing = new ThingT(); thing.ApplyValues(fields); // Return it return(thing); }