protected void Validate(CObject cObject) { if (cObject == null) throw new ArgumentNullException(string.Format( CommonStrings.XMustNotBeNull, "cObject")); const string methodName = "Validate"; try { System.Reflection.MethodInfo method = this.GetType().GetMethod(methodName, System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, Type.DefaultBinder, new Type[] { cObject.GetType() }, new System.Reflection.ParameterModifier[0]); if (method != null) { // Avoid StackOverflow exceptions by executing only if the method and visitable // are different from the last parameters used. if (method != lastCObjectMethod || cObject != lastCObject) { lastCObjectMethod = method; lastCObject = cObject; method.Invoke(this, new Object[] { cObject }); } else { string message = string.Format(CommonStrings.LoopingMethodTerminated, methodName, cObject.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY, methodName, cObject.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } catch (Exception ex) { if (ex.InnerException != null) if (ex.InnerException is ApplicationException && ex.InnerException.InnerException != null && ex.InnerException.Message == ex.InnerException.InnerException.Message) throw new ApplicationException(ex.InnerException.Message, ex.InnerException.InnerException); else throw new ApplicationException(ex.InnerException.Message, ex.InnerException); else throw new ApplicationException(ex.Message, ex); } }
private void ReadXml(CObject cObject) { if (cObject == null) throw new ArgumentNullException(string.Format(CommonStrings.XIsNull, "cObject")); const string methodName = "ReadXml"; try { System.Reflection.MethodInfo method = this.GetType().GetMethod(methodName, System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, Type.DefaultBinder, new Type[] { cObject.GetType() }, new System.Reflection.ParameterModifier[0]); if (method != null) { if (method != lastMethodReadCObject || cObject!= lastCObjectRead) { lastMethodReadCObject = method; lastCObjectRead = cObject; method.Invoke(this, new Object[] { cObject }); } else { string message = string.Format(CommonStrings.LoopingMethodTerminated, methodName, cObject.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY, methodName, cObject.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } catch (System.Reflection.TargetInvocationException ex) { if (ex.InnerException != null) throw new ApplicationException(ex.InnerException.Message, ex.InnerException); else throw new ApplicationException(ex.Message, ex); } }