public static void PopulateMapping(this IMappingObject this_, MappingWrapper mapping) { Type type = this_.GetType(); foreach (KeyValuePair <DataItem, DataItem> keyValuePair in mapping) { string text = "_" + keyValuePair.Key.GetTextOrDefault("").ToLower(); if (!(text == "_type")) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); FieldInfo fieldInfo = null; foreach (FieldInfo fieldInfo2 in fields) { if (fieldInfo2.Name.ToLower() == text) { fieldInfo = fieldInfo2; break; } } if (fieldInfo == null) { Log.Error(string.Format("[{0}] Member could not be found '{1}.{2}'", mapping.GetURL(), type.Name, text), new object[0]); } else { try { object value = keyValuePair.Value.ToType(fieldInfo.FieldType, mapping.Config); fieldInfo.SetValue(this_, value); } catch (Exception excaption) { Log.Exception(string.Format("[{0}] Exception while populateing member '{1}.{2}'", mapping.GetURL(), type.Name, text), excaption, new object[0]); } } } } }
private DataItem MergeNodes(DataItem prim, DataItem sec) { if (prim == null) { return(sec); } if (sec == null) { return(prim); } if (prim.GetType() != sec.GetType()) { return(prim); } //if (prim.EqualsContent(sec)) // return prim; Type dataType = prim.GetType(); if (dataType == typeof(Mapping)) { MappingWrapper mPri = new MappingWrapper(prim as Mapping, this); MappingWrapper mSec = new MappingWrapper(sec as Mapping, this); foreach (MappingEntry eSec in mSec.Mapping.Enties) { MappingEntry ePri = mPri.GetMappingNodeByKey(eSec.Key); if (ePri == null) { mPri.Add(eSec); } else { ePri.Value = this.MergeNodes(ePri.Value, eSec.Value); } } } else if (dataType == typeof(Sequence)) { Sequence sPri = prim as Sequence; Sequence sSec = sec as Sequence; foreach (DataItem item in sSec.Enties) { if (!sPri.Enties.ContainsItem(item)) { sPri.Enties.Add(item); } } } return(prim); }
public void ReadMapping(MappingWrapper mapping, YamlConfig config) { this._mapping = mapping; this.PopulateMapping(mapping); this.ReadMapping(mapping); }
protected virtual void ReadMapping(MappingWrapper mapping) { }