public virtual object BuildGenericMapInstance(MapObjectInfo mapObjectInfo, Type t) { System.Collections.Generic.IDictionary <AbstractObjectInfo, AbstractObjectInfo> map = mapObjectInfo.GetMap(); Type genericType = t.GetGenericTypeDefinition(); object newMap = null; try { newMap = System.Activator.CreateInstance(t); } catch (System.Exception e) { Console.WriteLine(e); throw new ODBRuntimeException(NeoDatisError.MapInstanciationError.AddParameter(map.GetType().FullName), e); } int i = 0; System.Collections.Generic.IEnumerator <AbstractObjectInfo> iterator = map.Keys.GetEnumerator(); AbstractObjectInfo key = null; MethodInfo method = t.GetMethod("Add", t.GetGenericArguments()); while (iterator.MoveNext()) { key = iterator.Current; object realKey = BuildOneInstance(key); object realValue = BuildOneInstance(map[key]); method.Invoke(newMap, new object[] { realKey, realValue }); } return(newMap); }
public virtual IDictionary BuildNonGenericMapInstance(MapObjectInfo mapObjectInfo, Type t) { System.Collections.Generic.IDictionary <AbstractObjectInfo, AbstractObjectInfo> map = mapObjectInfo.GetMap(); IDictionary newMap; try { newMap = (IDictionary)System.Activator.CreateInstance(t); } catch (System.Exception e) { throw new ODBRuntimeException(NeoDatisError.MapInstanciationError.AddParameter(map.GetType().FullName), e); } int i = 0; System.Collections.Generic.IEnumerator <AbstractObjectInfo> iterator = map.Keys.GetEnumerator(); AbstractObjectInfo key = null; while (iterator.MoveNext()) { key = iterator.Current; object realKey = BuildOneInstance(key); object realValue = BuildOneInstance(map[key]); newMap[realKey] = realValue; } return(newMap); }