protected void ValidateBase(State state) { Invariant(!string.IsNullOrEmpty(state.Name), "state.Name must not be null or empty."); }
protected void Validate(State state) { if (state == null) throw new ArgumentNullException("state must not be null."); 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[] { state.GetType() }, new System.Reflection.ParameterModifier[0]); if (method != null) { if (method != lastStateMethod || state != lastState) { lastStateMethod = method; lastState = state; method.Invoke(this, new Object[] { state }); } else { string message = "The method '" + methodName + "' with parameter type '" + state.GetType().ToString() + "' is looping and is terminated."; System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = "The method '" + methodName + "' with parameter type '" + state.GetType().ToString() + "' is not implemented."; 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 WriteXmlBase(State state) { Check.Require(state != null, string.Format(CommonStrings.XMustNotBeNull, "state")); Check.Require(!string.IsNullOrEmpty(state.Name), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "state.Name")); writer.WriteElementString(UseOpenEhrPrefix(writer), "name", OpenEhrNamespace, state.Name); }
private void WriteXml(State state) { if (state == null) throw new ArgumentNullException(string.Format(CommonStrings.XIsNull, "state")); 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[] { state.GetType() }, new System.Reflection.ParameterModifier[0]); if (method != null) { if (method != lastMethodWriteXmlState || state != lastStateWrite) { lastMethodWriteXmlState = method; lastStateWrite = state; method.Invoke(this, new Object[] { state }); } else { string message = string.Format(CommonStrings.LoopingMethodTerminated, methodName, state.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY, methodName, state.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); } }
private void ReadXmlBase(State state) { if(reader.LocalName !="name") throw new InvalidXmlException("name", reader.LocalName); state.Name = reader.ReadElementContentAsString("name", OpenEhrNamespace); }
private void ReadXml(State state) { if (state == null) throw new ArgumentNullException("state must not be null."); 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[] { state.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 != lastMethodReadStateType || state != lastStateRead) { lastMethodReadStateType = method; lastStateRead = state; method.Invoke(this, new Object[] { state }); } else { string message = string.Format(CommonStrings.LoopingMethodTerminated, methodName, state.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY, methodName, state.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); } }