예제 #1
0
        protected void Validate(CPrimitive cPrimitive)
        {
            if (cPrimitive == null) throw new ArgumentNullException(string.Format(
                CommonStrings.XMustNotBeNull, "cPrimitive"));

            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[] { cPrimitive.GetType() },
                               new System.Reflection.ParameterModifier[0]);

                if (method != null)
                {
                    if (method != lastCPrimitiveMethod || cPrimitive != lastCPrimitive)
                    {
                        lastCPrimitiveMethod = method;
                        lastCPrimitive = cPrimitive;

                        method.Invoke(this, new Object[] { cPrimitive });

                    }
                    else
                    {
                        string message = string.Format(CommonStrings.LoopingMethodTerminated,
                            methodName, cPrimitive.GetType().ToString());
                        System.Diagnostics.Debug.WriteLine(message);
                        throw new ApplicationException(message);
                    }
                }
                else
                {
                    string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY,
                        methodName, cPrimitive.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);
            }
        }
예제 #2
0
        private void WriteXml(CPrimitive cPrimitiveObj)
        {
            if (cPrimitiveObj == null) throw new ArgumentNullException(string.Format(CommonStrings.XIsNull, "cPrimitiveObj"));

            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[] { cPrimitiveObj.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 != lastMethodWriteXmlCPrimitive || cPrimitiveObj != lastCPrimitiveWrite)
                    {
                        lastMethodWriteXmlCPrimitive = method;
                        lastCPrimitiveWrite = cPrimitiveObj;

                        method.Invoke(this, new Object[] { cPrimitiveObj });

                    }
                    else
                    {
                        string message = string.Format(CommonStrings.LoopingMethodTerminated,
                            methodName, cPrimitiveObj.GetType().ToString());
                        System.Diagnostics.Debug.WriteLine(message);
                        throw new ApplicationException(message);
                    }
                }
                else
                {
                    string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY,
                        methodName, cPrimitiveObj.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);
            }
        }