public void extractObject1Test() { //TreeMap<string, CarOptions> tree_; //tree_ = new TreeMap<string, CarOptions>(); //tree_.put("hello", CarOptions.FogLights); Assert.AreEqual("FogLights", FormatHtml.extractObject("ToString()", CarOptions.FogLights)); }
public void extractObject3Test() { Pair <int, string> p_ = new Pair <int, string>(); p_.setFirst(0); p_.setSecond("str"); Assert.AreEqual("str", FormatHtml.extractObject("Util^Util^Pair^2^second", p_)); }
private void updateBean(Map <String, String> _inputClasses, Map <String, String> _changing, Map <String, String> _query, Map <String, String> _varMethods) { Type strType_ = typeof(string); foreach (String k in _query.getKeys()) { if (k.isEmpty()) { continue; } String simpleKey_ = k; String beanName_ = k.Substring(0, k.IndexOf(DOT)); Bean bean_ = session.getBeans().getVal(beanName_); String v_ = _query.getVal(k); String varMethod_ = _varMethods.getVal(k); simpleKey_ = k.Substring(k.IndexOf(DOT) + 1); Object obj_ = FormatHtml.extractObject(simpleKey_, bean_); Match m_ = new Regex(REG_EXP_POSITIVE_INT).Match(simpleKey_); MyList <long> indexes_ = new MyList <long>(); if (m_.Success) { int nb_ = m_.Groups.Count; for (int i = 1; i <= nb_; i++) { indexes_.Add(long.Parse(m_.Groups[i].Value)); } } String changingValue_ = EMPTY_STRING; if (_changing.contains(k)) { String method_ = _changing.getVal(k); try { //checking for existence of method_ in the bean class bean_.GetType().GetMethod(method_, new Type[] { typeof(ValueChangeEvent) }); changingValue_ = method_; } catch (Exception) { } } String className_ = _inputClasses.getVal(k); if (className_.StartsWith(".")) { className_ = session.getAssembly() + className_; } className_ = className_.Replace(".]", session.getAssembly() + "]"); if (obj_ == null) { //case where it is better to test on class of the value Type class_ = Constants.classForName(className_); if (class_.IsEnum) { bool success_ = false; //Enum foreach (Enum o in class_.GetEnumValues()) { if (o.name().Equals(v_)) { //The field value is an enum value FormatHtml.setObject(bean_, simpleKey_, varMethod_, o, changingValue_, className_, indexes_); success_ = true; break; } } if (!success_) { //throw new InexistingValueForEnum(v_, class_.Name); throw new InexistingValueForEnum(); } continue; } /*try { * bool success_ = false; * //Enum * for (Enum<?> o : class_.asSubclass(Enum.class).getEnumConstants()) { * if (o.name().equals(v_)) { * //The field value is an enum value * FormatHtml.setObject(bean_, simpleKey_, varMethod_, o, * changingValue_, className_, indexes_); * success_ = true; * break; * } * } * if (!success_) { * throw new InexistingValueForEnum(v_, class_.getName()); * } * continue; * } catch (ClassCastException e) { * }*/ //Boolean if (class_ == typeof(Boolean)) { FormatHtml.setObject(bean_, simpleKey_, varMethod_, v_.Equals(ON), changingValue_, className_, indexes_); continue; } //Number if (class_.IsValueType) { MethodInfo methNb_ = Constants.getParseMethod(class_); //ConstructorInfo c_ = class_.GetConstructor(new Type[] { strType_ }); object objNew_ = methNb_.Invoke(null, new object[] { v_ }); FormatHtml.setObject(bean_, simpleKey_, varMethod_, objNew_, changingValue_, className_, indexes_); continue; } //Number /*try { * class_.asSubclass(Number.class); * FormatHtml.setObject(bean_, simpleKey_, varMethod_, class_ * .getConstructor(String.class) * .newInstance(v_), changingValue_, * className_, indexes_); * continue; * } catch (ClassCastException e) { * }*/ //Primitivable if (typeof(Primitivable).IsAssignableFrom(class_)) { ConstructorInfo c_ = class_.GetConstructor(new Type[] { strType_ }); object objNew_ = c_.Invoke(new object[] { v_ }); FormatHtml.setObject(bean_, simpleKey_, varMethod_, objNew_, changingValue_, className_, indexes_); continue; } /*try { * class_.asSubclass(Primitivable.class); * FormatHtml.setObject(bean_, simpleKey_, varMethod_, class_ * .getConstructor(String.class) * .newInstance(v_), changingValue_, * className_, indexes_); * continue; * } catch (ClassCastException e) { * }*/ FormatHtml.setObject(bean_, simpleKey_, varMethod_, v_, changingValue_, className_, indexes_); continue; } //Enum if (obj_ is Enum) { bool success_ = false; foreach (Enum o in obj_.GetType().GetEnumValues()) { if (o.name().Equals(v_)) { //The field value is an enum value FormatHtml.setObject(bean_, simpleKey_, varMethod_, o, changingValue_, className_, indexes_); success_ = true; break; } } /*for (Enum<?> o : obj_.getClass().asSubclass(Enum.class) * .getEnumConstants()) { * if (o.name().equals(v_)) { * FormatHtml.setObject(bean_, simpleKey_, varMethod_, o, * changingValue_, className_, indexes_); * success_ = true; * break; * } * }*/ /*if (!success_) { * throw new InexistingValueForEnum(v_, obj_.getClass().getName()); * }*/ if (!success_) { //throw new InexistingValueForEnum(v_, class_.Name); throw new InexistingValueForEnum(); } continue; } //Boolean if (obj_ is Boolean) { FormatHtml.setObject(bean_, simpleKey_, varMethod_, v_.Equals(ON), changingValue_, className_, indexes_); continue; } //Number, Primitivable if (obj_.GetType().IsValueType) { MethodInfo methNb_ = Constants.getParseMethod(obj_.GetType()); //ConstructorInfo c_ = obj_.GetType().GetConstructor(new Type[] { strType_ }); object objNew_ = methNb_.Invoke(null, new object[] { v_ }); FormatHtml.setObject(bean_, simpleKey_, varMethod_, objNew_, changingValue_, className_, indexes_); continue; } if (obj_ is Primitivable) { ConstructorInfo c_ = obj_.GetType().GetConstructor(new Type[] { strType_ }); object objNew_ = c_.Invoke(new object[] { v_ }); FormatHtml.setObject(bean_, simpleKey_, varMethod_, objNew_, changingValue_, className_, indexes_); continue; } FormatHtml.setObject(bean_, simpleKey_, varMethod_, v_, changingValue_, className_, indexes_); } }
public void extractObject4Test() { Assert.AreEqual("ONE", FormatHtml.extractObject("FormatHtmlTests^FormatHtmlTests^BeanOne^selectedString", new BeanOne())); }