protected void Validate(ExprItem exprItem) { if (exprItem == null) throw new ArgumentNullException(string.Format( CommonStrings.XMustNotBeNull, "exprItem")); 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[] { exprItem.GetType() }, new System.Reflection.ParameterModifier[0]); if (method != null) { if (method != lastExprItemMethodRead || exprItem != lastExprItem) { lastExprItemMethodRead = method; lastExprItem = exprItem; method.Invoke(this, new Object[] { exprItem }); } else { string message = string.Format(CommonStrings.LoopingMethodTerminated, methodName, exprItem.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY, methodName, exprItem.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 WriteXml(ExprItem exprItem) { if (exprItem == null) throw new ArgumentNullException(string.Format(CommonStrings.XIsNull, "exprItem")); const string methodName = "WriteXml"; 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[] { exprItem.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 != lastMethodWriteXmlExprItem || exprItem != lastExprItemWrite) { lastMethodWriteXmlExprItem = method; lastExprItemWrite = exprItem; method.Invoke(this, new Object[] { exprItem }); } else { string message = string.Format(CommonStrings.LoopingMethodTerminated, methodName, exprItem.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY, methodName, exprItem.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); } }