//------------------------------------------------------------------------- /// <summary> /// Test an enum for the primary purpose of increasing test coverage. /// </summary> /// @param <E> the enum type </param> /// <param name="clazz"> the class to test </param> public static void coverEnum <E>(Type <E> clazz) where E : Enum <E> { assertNotNull(clazz, "coverEnum() called with null class"); ignoreThrows(() => { System.Reflection.MethodInfo method = clazz.getDeclaredMethod("values"); method.Accessible = true; method.invoke(null); }); foreach (E val in clazz.EnumConstants) { ignoreThrows(() => { System.Reflection.MethodInfo method = clazz.getDeclaredMethod("valueOf", typeof(string)); method.Accessible = true; method.invoke(null, val.name()); }); } ignoreThrows(() => { System.Reflection.MethodInfo method = clazz.getDeclaredMethod("valueOf", typeof(string)); method.Accessible = true; method.invoke(null, ""); }); ignoreThrows(() => { System.Reflection.MethodInfo method = clazz.getDeclaredMethod("valueOf", typeof(string)); method.Accessible = true; method.invoke(null, (object)null); }); }
internal override object get(ObjectRepresentation @object) { Exception e; try { return(_method.invoke(@object)); } catch (InvocationTargetException ex) { e = ex.TargetException; if (e is Exception) { throw ( Exception )e; } else if (e is Exception) { throw ( Exception )e; } } catch (Exception ex) { e = ex; } throw new System.InvalidOperationException("Serialization failure", e); }
public static object invoke(object target, string methodName, object[] args) { try { Type clazz = target.GetType(); System.Reflection.MethodInfo method = findMethod(clazz, methodName, args); method.Accessible = true; return(method.invoke(target, args)); } catch (Exception e) { throw LOG.exceptionWhileInvokingMethod(methodName, target, e); } }