public override void setElementSerial(ElementsSerial _e, ElementsSerial _newE) { string str_ = _e.getClassName(); Type class_; if (str_.Contains(SPECIAL_SEP)) { string types_ = str_.Substring(str_.IndexOf(SPECIAL_SEP)); class_ = Constants.classForName(str_, types_); } else { class_ = Constants.classForName(str_); } FieldInfo field_ = SerializeXmlObject.getField(class_, _e.getField()); field_.SetValue(value, _newE.getValue()); /*for (Field f: cl_.getDeclaredFields()) { * if (!f.getName().equals(_e.getField())) * { * continue; * } * if (!SerializeXmlObject.isUpdateFinalFields()) * { * if (Modifier.isFinal(f.getModifiers())) * { * continue; * } * } * f.setAccessible(cl_.getAnnotation(RwXml.class)!=null); * f.set(value, _newE.getValue()); * break; * }*/ }
public override void appendElementSerialWithoutRef(MyList <ElementsSerial> _elt) { foreach (ElementsSerial e in _elt) { string str_ = e.getClassName(); Type class_; if (str_.Contains(SPECIAL_SEP)) { string types_ = str_.Substring(str_.IndexOf(SPECIAL_SEP)); class_ = Constants.classForName(str_, types_); } else { class_ = Constants.classForName(str_); } FieldInfo field_ = SerializeXmlObject.getField(class_, e.getField()); field_.SetValue(value, e.getValue()); } /*for (ElementsSerial e: _elt) { * Class <?> cl_ = Constants.classForName(e.getClassName()); * for (Field f: cl_.getDeclaredFields()) * { * if (!f.getName().equals(e.getField())) * { * continue; * } * if (!SerializeXmlObject.isUpdateFinalFields()) * { * if (Modifier.isFinal(f.getModifiers())) * { * continue; * } * } * f.setAccessible(cl_.getAnnotation(RwXml.class)!=null); * f.set(value, e.getValue()); * break; * } * } * }*/ }
public override void appendElementSerialWithoutRef(MyList <ElementsSerial> _elt) { keys = new MyList <object>(); values = new MyList <object>(); MethodInfo ADD_METHOD = value.GetType().GetMethod("Add", types); foreach (ElementsSerial e in _elt) { if (e is ComparatorSerial) { continue; } Type t_ = typeof(IEnumerable); string fullType_ = Constants.getTypeFullString(t_); if (fullType_.ToLower().Equals(e.getClassName().ToLower())) { object obj_ = e.getValue(); /*if (obj_ != null) * { * if (obj_.GetType().IsPrimitive) * { * if (types.ElementAt(0).IsEnum) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * if (types.ElementAt(0).IsPrimitive) * { * if (obj_.GetType().IsEnum) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * }*/ ADD_METHOD.Invoke(value, new object[] { obj_ }); continue; } /*if (typeof(IEnumerable).FullName.ToLower().Equals(e.getClassName().ToLower())) * { * ADD_METHOD.Invoke(value, new object[] { e.getValue() }); * continue; * }*/ } foreach (ElementsSerial e in _elt) { if (e is ComparatorSerial) { cmpSerial = (ComparatorSerial)e; continue; } Type t_ = typeof(ListableKey); string fullType_ = Constants.getTypeFullString(t_); if (!fullType_.ToLower().Equals(e.getClassName().ToLower())) { continue; } object obj_ = e.getValue(); /*if (!typeof(ListableKey).FullName.ToLower().Equals(e.getClassName().ToLower())) * { * continue; * }*/ /*if (!e.getClassName().equalsIgnoreCase(Map.class.getName())) { * continue; * }*/ if (!e.isKeyOfMap()) { /*if (obj_ != null) * { * if (obj_.GetType().IsPrimitive) * { * if (types.ElementAt(1).IsEnum) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * if (types.ElementAt(1).IsPrimitive) * { * if (obj_.GetType().IsEnum) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * }*/ values.Add(e.getValue()); } else { /*if (obj_ != null) * { * if (obj_.GetType().IsPrimitive) * { * if (types.ElementAt(0).IsEnum) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * if (types.ElementAt(0).IsPrimitive) * { * if (obj_.GetType().IsEnum) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * }*/ keys.Add(e.getValue()); } } foreach (ElementsSerial e in _elt) { if (e is ComparatorSerial) { continue; } Type t_ = typeof(IEnumerable); string fullType_ = Constants.getTypeFullString(t_); //Console.WriteLine(e.getClassName() + "%%" + fullType_); /*Type t2_ = typeof(IEnumerable); * string str2_ = ElementsSerial.getType(t_); * string assName2_ = t_.Assembly.GetName().Name; * string fullType2_ = assName_ + ".." + str_;*/ if (fullType_.ToLower().Equals(e.getClassName().ToLower())) { continue; } t_ = typeof(ListableKey); fullType_ = Constants.getTypeFullString(t_); if (fullType_.ToLower().Equals(e.getClassName().ToLower())) { continue; } /*if (typeof(IEnumerable).FullName.ToLower().Equals(e.getClassName().ToLower())) * { * continue; * } * if (typeof(ListableKey).FullName.ToLower().Equals(e.getClassName().ToLower())) * { * continue; * }*/ /*if (e.getClassName().equalsIgnoreCase(List.class.getName())) { * continue; * } * if (e.getClassName().equalsIgnoreCase(Map.class.getName())) { * continue; * }*/ //Type class_ = Constants.classForName(e.getClassName()); string str_ = e.getClassName(); Type class_; if (str_.Contains(SPECIAL_SEP)) { string types_ = str_.Substring(str_.IndexOf(SPECIAL_SEP)); class_ = Constants.classForName(str_, types_); } else { class_ = Constants.classForName(str_); } if (!class_.IsInstanceOfType(value)) { continue; } /*FieldInfo field_ = class_.GetField(e.getField(), BindingFlags.NonPublic | * BindingFlags.Instance);*/ FieldInfo field_ = SerializeXmlObject.getField(class_, e.getField()); object obj_ = e.getValue(); /*if (obj_ != null) * { * if (obj_.GetType().IsPrimitive) * { * if (field_.FieldType.IsEnum) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * if (obj_.GetType().IsEnum) * { * if (field_.FieldType.IsPrimitive) * { * throw new ArgumentException(); * //Console.WriteLine("%%%"+ obj_); * } * } * }*/ /*if (!SerializeXmlObject.isUpdateFinalFields()) { * if (Modifier.isFinal(field_.getModifiers())) { * continue; * } * } * if (Modifier.isStatic(field_.getModifiers())) { * continue; * }*/ //field_.setAccessible(class_.getAnnotation(RwXml.class)!=null); field_.SetValue(value, e.getValue()); } if (value is ListableKey && !(value is IComparableKeys)) { FieldInfo LIST_FIELD = value.GetType().GetField("list", BindingFlags.NonPublic | BindingFlags.Instance); Object list_ = LIST_FIELD.GetValue(value); ADD_METHOD = list_.GetType().GetMethod("Add"); Type treeMapTypeGene_ = typeof(Map <,>); //string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + ".." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name; string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + "." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name; treeMapType_ = treeMapType_.Substring(0, treeMapType_.IndexOf(ElementsSerial.SPECIAL_SEP) + 1); Type curType_ = value.GetType(); while (true) { if (curType_ == null) { break; } if (Constants.getTypeFullString(curType_).StartsWith(treeMapType_)) { break; } curType_ = curType_.BaseType; } Type[] args_ = curType_.GetGenericArguments(); Type genericType_ = typeof(Entry <,>).MakeGenericType(args_); ConstructorInfo ctor_ = genericType_.GetConstructor(args_); int len_ = keys.size(); for (int i = 0; i < len_; i++) { //PUT_METHOD.invoke(value, keys.get(i),values.get(i)); object e_ = ctor_.Invoke(new object[] { keys.get(i), values.get(i) }); ADD_METHOD.Invoke(list_, new object[] { e_ }); } keys.Clear(); values.Clear(); } if (value is IComparableKeys) { Type treeMapTypeGene_ = typeof(TreeMap <,>); //string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + ".." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name; string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + "." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name; treeMapType_ = treeMapType_.Substring(0, treeMapType_.IndexOf(ElementsSerial.SPECIAL_SEP) + 1); Type curType_ = value.GetType(); while (true) { if (curType_ == null) { break; } if (Constants.getTypeFullString(curType_).StartsWith(treeMapType_)) { break; } curType_ = curType_.BaseType; } Type[] args_ = curType_.GetGenericArguments(); if (cmpSerial != null) { Type dicoMapType_; // = typeof(SortedDictionary<,>); Type speTreeMapType_; // = dicoMapType_.MakeGenericType(args_); /*foreach (PropertyInfo p in SerializeXmlObject.getProperties(speTreeMapType_)) * { * Console.WriteLine(p.Name); * }*/ //PropertyInfo p_ = SerializeXmlObject.getProperty(speTreeMapType_, COMPARATOR); //f_.setAccessible(true); //Console.WriteLine(cmpSerial.getValue().GetType()); //Console.WriteLine(p_.PropertyType); //p_.GetSetMethod(true) //p_.GetSetMethod(true).Invoke(value, new object[] { cmpSerial.getValue() }); //p_.SetValue(value, cmpSerial.getValue()); dicoMapType_ = typeof(TreeMap <,>); speTreeMapType_ = dicoMapType_.MakeGenericType(args_); FieldInfo f_ = SerializeXmlObject.getField(speTreeMapType_, "comparator"); //f_.setAccessible(true); f_.SetValue(value, cmpSerial.getValue()); } MethodInfo m_ = curType_.GetMethod("put", args_); int len_ = keys.size(); for (int i = 0; i < len_; i++) { m_.Invoke(value, new object[] { keys.get(i), values.get(i) }); } keys.Clear(); values.Clear(); } /*if (PairUtil.isMap(value)) { * * }*/ }
public override void appendElementSerial(MyList <ElementsSerial> _elt) { indexesRef = new Map <int?, long?>(); int i_ = 0; keys = new MyList <object>(); keysIndexesRef = new Map <int?, long?>(); int iKey_ = 0; values = new MyList <object>(); valuesIndexesRef = new Map <int?, long?>(); int iValue_ = 0; MethodInfo ADD_METHOD = value.GetType().GetMethod("Add"); foreach (ElementsSerial e in _elt) { if (e is ComparatorSerial) { continue; } if (typeof(IEnumerable).FullName.ToLower().Equals(e.getClassName().ToLower())) { if (e is TemplateSerial) { if (((TemplateSerial)e).getRef() != null) { indexesRef.put(i_, ((TemplateSerial)e).getRef()); } } ADD_METHOD.Invoke(value, new object[] { e.getValue() }); i_++; continue; } } foreach (ElementsSerial e in _elt) { if (e is ComparatorSerial) { cmpSerial = (ComparatorSerial)e; continue; } //ListableKey // if (!typeof(ListableKey).FullName.ToLower().Equals(e.getClassName().ToLower())) { continue; } /*if (!e.getClassName().equalsIgnoreCase(Map.class.getName())) { * continue; * }*/ if (!e.isKeyOfMap()) { if (e is TemplateSerial) { if (((TemplateSerial)e).getRef() != null) { valuesIndexesRef.put(iValue_, ((TemplateSerial)e).getRef()); } } values.Add(e.getValue()); iValue_++; } else { if (e is TemplateSerial) { if (((TemplateSerial)e).getRef() != null) { keysIndexesRef.put(iKey_, ((TemplateSerial)e).getRef()); } } keys.Add(e.getValue()); iKey_++; } } foreach (ElementsSerial e in _elt) { if (e is ComparatorSerial) { continue; } Type t_ = typeof(IEnumerable); string fullType_ = Constants.getTypeFullString(t_); if (fullType_.ToLower().Equals(e.getClassName().ToLower())) { continue; } t_ = typeof(ListableKey); fullType_ = Constants.getTypeFullString(t_); if (fullType_.ToLower().Equals(e.getClassName().ToLower())) { continue; } /*if (e.getClassName().equalsIgnoreCase(List.class.getName())) { * continue; * } * if (e.getClassName().equalsIgnoreCase(Map.class.getName())) { * continue; * }*/ string str_ = e.getClassName(); Type class_; if (str_.Contains(SPECIAL_SEP)) { string types_ = str_.Substring(str_.IndexOf(SPECIAL_SEP)); class_ = Constants.classForName(str_, types_); } else { class_ = Constants.classForName(str_); } if (!class_.IsInstanceOfType(value)) { continue; } //FieldInfo field_ = class_.GetField(e.getField(), BindingFlags.NonPublic | // BindingFlags.Instance); FieldInfo field_ = SerializeXmlObject.getField(class_, e.getField()); /*if (!SerializeXmlObject.isUpdateFinalFields()) { * if (Modifier.isFinal(field_.getModifiers())) { * continue; * } * }*/ /*if (Modifier.isStatic(field_.getModifiers())) { * continue; * }*/ //field_.setAccessible(class_.getAnnotation(RwXml.class)!=null); field_.SetValue(value, e.getValue()); } }
public void initializeObjectsWithoutIdRef() { bool modif_ = true; while (modif_) { modif_ = false; setNews(new MyList <TemplateSerial>()); foreach (TemplateSerial e in getCurrents()) { setComponents(new MyList <ElementsSerial>()); Object currentValue_ = e.getValue(); if (currentValue_ is IEnumerable && !currentValue_.GetType().IsArray) { /*bool treeMap_ = false; * Type treeMapTypeGene_ = typeof(TreeMap<,>); * string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name+".."+ treeMapTypeGene_.Namespace+"."+ treeMapTypeGene_.Name; * treeMapType_ = treeMapType_.Substring(0, treeMapType_.IndexOf(ElementsSerial.SPECIAL_SEP) + 1); * Type curType_ = currentValue_.GetType(); * while (true) * { * if (curType_ == null) * { * break; * } * if (Constants.getTypeFullString(curType_).StartsWith(treeMapType_)) * { * treeMap_ = true; * break; * } * curType_ = curType_.BaseType; * } * if (treeMap_) * { * Type[] args_ = curType_.GetGenericArguments(); * Type pairType_ = typeof(KeyValuePair<,>).MakeGenericType(args_); * foreach (Object o in (IEnumerable)currentValue_) * { * if (pairType_.IsInstanceOfType(o)) * { * continue; * } * addElementInListWithoutIdRef(o); * } * } else * { * foreach (Object o in (IEnumerable)currentValue_) * { * addElementInListWithoutIdRef(o); * } * }*/ foreach (Object o in (IEnumerable)currentValue_) { addElementInListWithoutIdRef(o); } /*Type[] args_ = currentValue_.GetType().GetGenericArguments(); * Type pairType_ = null; * if (args_.Length == 2) * { * Type spec_ = typeof(TreeMap<,>).MakeGenericType(args_); * pairType_ = typeof(KeyValuePair<,>).MakeGenericType(args_); * if (spec_.IsInstanceOfType(currentValue_)) * { * treeMap_ = true; * } * } * if (treeMap_) * { * foreach (Object o in (IEnumerable)currentValue_) * { * if (pairType_.IsInstanceOfType(o)) * { * continue; * } * addElementInListWithoutIdRef(o); * } * }*/ } if (currentValue_ is ListableKey) { /*if (currentValue_ instanceof TreeNodeMap) { * Object value_ = ((TreeNodeMap <?,?>)currentValue_).getCmp(); * addElementInMapWithoutIdRef(value_, true, true); * }else if (currentValue_ instanceof TreeMap * * && !(currentValue_ instanceof NaturalTreeNodeMap)) { * Object value_ = ((TreeMap <?,?>)currentValue_).comparator(); * if (value_ != null) * { * addElementInMapWithoutIdRef(value_, false, true); * } * }*/ // List<Object> keys_ = new List<>(); // for (Object o: ((Map<?,?>)currentValue_).keySet()) { // keys_.add(o); // } // for (Object o: keys_) { // addElementInMapWithoutIdRef(o,true, false); // // } // for (Object o: keys_) { // Object value_ = ((Map<?,?>)currentValue_).get(o); // addElementInMapWithoutIdRef(value_,false, false); // } bool treeMap_ = false; Type treeMapTypeGene_ = typeof(TreeMap <,>); //string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + ".." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name; string treeMapType_ = treeMapTypeGene_.Assembly.GetName().Name + "." + treeMapTypeGene_.Namespace + "." + treeMapTypeGene_.Name; treeMapType_ = treeMapType_.Substring(0, treeMapType_.IndexOf(ElementsSerial.SPECIAL_SEP) + 1); Type curType_ = currentValue_.GetType(); while (true) { if (curType_ == null) { break; } if (Constants.getTypeFullString(curType_).StartsWith(treeMapType_)) { treeMap_ = true; break; } curType_ = curType_.BaseType; } if (treeMap_) { FieldInfo p_ = SerializeXmlObject.getField(curType_, "comparator"); object cmp_ = p_.GetValue(currentValue_); if (cmp_ != null) { addElementInMapWithoutIdRef(cmp_, false, true); } } ListableKey l_ = (ListableKey)currentValue_; foreach (IEntry k in l_.entryListGene()) { addElementInMapWithoutIdRef(k.getKeyObj(), true, false); addElementInMapWithoutIdRef(k.getValueObj(), false, false); } } if (currentValue_.GetType().IsArray) { Array array_ = currentValue_ as Array; int length_ = array_.Length; for (int i = 0; i < length_; i++) { addElementInArrayWithoutIdRef(array_.GetValue(i)); } addComponentsToComposite(e); continue; } /*if (currentValue_.getClass().isArray()) * { * int length_ = Array.getLength(currentValue_); * for (int i = Constants.getFirstIndex(); i < length_; i++) * { * addElementInArrayWithoutIdRef(Array.get(currentValue_, i)); * } * }*/ Type cl_; if (getAllImplicitComparators().containsObj(e)) { cl_ = currentValue_.GetType(); while (cl_ != typeof(Object)) { bool comparatorClass_ = typeof(Comparer).IsAssignableFrom(cl_); //try { // cl_.asSubclass(Comparator.class); // comparatorClass_ = true; //} catch (Exception _e) { //} if (!comparatorClass_) { break; } foreach (FieldInfo f in SerializeXmlObject.getFields(cl_)) { if (f.IsNotSerialized) { continue; } //if (Modifier.isTransient(f.getModifiers())) { // if (!SerializeXmlObject.isCopying()) { // continue; // } //} //if (Modifier.isStatic(f.getModifiers())) { // continue; //} //f.setAccessible(cl_.getAnnotation(RwXml.class)!=null); Object value_ = f.GetValue(currentValue_); addElementInSerializableWithoutIdRef(value_, cl_, f.Name); } cl_ = cl_.BaseType; } addComponentsToComposite(e); continue; } cl_ = currentValue_.GetType(); while (cl_ != null) { Type base_ = cl_.BaseType; if (base_ == null) { break; } string name_ = base_.Name; if (name_.ToLower().StartsWith(typeof(List <object>).Name.ToLower())) { break; } if (cl_.Name.ToLower().StartsWith(typeof(Map <object, object>).Name.ToLower())) { break; } if (cl_.Name.ToLower().StartsWith(typeof(TreeMap <object, object>).Name.ToLower())) { break; } /*if (cl_.getSuperclass() == AbstractList.class) { * break; * }*/ /*if (cl_.getSuperclass() == AbstractMap.class) { * break; * }*/ foreach (FieldInfo f in SerializeXmlObject.getFields(cl_)) { if (f.IsNotSerialized) { continue; } /*if (Modifier.isTransient(f.getModifiers())) { * if (!SerializeXmlObject.isCopying()) { * continue; * } * }*/ /*if (Modifier.isStatic(f.getModifiers())) { * continue; * }*/ //f.setAccessible(cl_.getAnnotation(RwXml.class)!=null); Object value_ = f.GetValue(currentValue_); addElementInSerializableWithoutIdRef(value_, cl_, f.Name); } cl_ = cl_.BaseType; } addComponentsToComposite(e); } if (!getNews().isEmpty()) { modif_ = true; setCurrents(new MyList <TemplateSerial>(getNews())); } } }