Ejemplo n.º 1
0
        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]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public IMappingObject GetMappingObject(DataItem item)
        {
            if (!(item is Mapping))
            {
                Log.Warn(string.Format("Item ({0}): Should be a \"Mapping\", but is a \"{1}\"", this.GetURL(item), item.GetType().Name));
                return(null);
            }
            Type type = item.GetNodeType();

            if (type == null)
            {
                Log.Warn(string.Format("Item ({0}): Type '{1}' not found",
                                       this.GetURL(item),
                                       new MappingWrapper((item as Mapping), this).GetOrDef("type", "NO TYPE DEFINED")
                                       ));
                return(null);
            }
            if (!type.IsIMappingObject())
            {
                Log.Warn(string.Format("Item ({0}): Type '{1}' is not castable to 'IMappingObject'", this.GetURL(item), type.Name));
                return(null);
            }
            IMappingObject obj = null;

            if (item.GetAnchor() != null)
            {
                if (this._refObjects.ContainsKey(item.GetAnchor()))
                {
                    obj = this._refObjects[item.GetAnchor()];
                }
            }
            if (obj == null)
            {
                obj = (IMappingObject)Activator.CreateInstance(type);
                obj.ReadMapping(new MappingWrapper(item as Mapping, this), this);
                if (item.GetAnchor() != null && !this._refObjects.ContainsKey(item.GetAnchor()))
                {
                    this._refObjects.Add(item.GetAnchor(), obj);
                }
            }
            return(obj);
        }
Ejemplo n.º 3
0
 public MappingPair(IMappingObject src, IMappingObject dest)
 {
     Src  = src;
     Dest = dest;
 }