protected virtual object Visit(openehr.openehr.am.archetype.constraint_model.C_OBJECT o, int depth)
        {
            if (o == null)
                throw new ArgumentNullException("CObject parameter must not be null.  depth = " + depth);

            try
            {
                System.Reflection.MethodInfo method = this.GetType().GetMethod("Visit",
                               System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.NonPublic
                               | System.Reflection.BindingFlags.Instance, Type.DefaultBinder,
                               new Type[] { o.GetType(), depth.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 != lastMethod || o != lastObject)
                    {
                        lastMethod = method;
                        lastObject = o;
                        object itemObject = method.Invoke(this, new object[] { o, depth });

                        return itemObject;
                    }
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                if (ex.InnerException != null)
                {
                    if (ex.InnerException.InnerException != null)
                    {
                        //System.Diagnostics.Debug.WriteLine(ex.InnerException.InnerException.ToString() + Environment.NewLine);
                        //throw ex.InnerException;
                        throw new InvalidOperationException("Visit Exeception.  depth = " + depth, ex.InnerException.InnerException);
                    }
                    System.Diagnostics.Debug.WriteLine(ex.InnerException.ToString() + Environment.NewLine);
                    //throw ex.InnerException;
                    throw new InvalidOperationException("Visit Exeception", ex.InnerException);
                }
                System.Diagnostics.Debug.WriteLine(ex.ToString() + Environment.NewLine + depth);
                //throw;
                throw new InvalidOperationException("Visit Exeception", ex);
            }
            catch (InvalidOperationException ex)
            {
                if (ex.InnerException != null)
                {
                    System.Diagnostics.Debug.WriteLine(ex.InnerException.ToString() + Environment.NewLine);
                    //throw ex.InnerException;
                    throw new InvalidOperationException("Visit Exeception", ex.InnerException);
                }
                System.Diagnostics.Debug.WriteLine(ex.ToString() + Environment.NewLine + depth);
                //throw;
                throw new InvalidOperationException("Visit Exeception", ex);
            }

            throw new NotImplementedException("The Visitor method 'Visit' with parameter type '" + o.GetType().ToString() + "' is not implemented.");
        }
        protected virtual C_PRIMITIVE CloneC_Primitive(openehr.openehr.am.archetype.constraint_model.primitive.C_PRIMITIVE o)
        {
            string typeName = o.GetType().Name;
            typeName = typeName.ToUpper();

            switch (typeName)
            {
                case "C_REAL":
                    return CloneReal(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_REAL);

                case "C_INTEGER":
                    return CloneInteger(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_INTEGER);

                case "C_STRING":
                    return CloneString(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_STRING);

                case "C_BOOLEAN":
                    return CloneBoolean(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_BOOLEAN);

                case "C_DURATION":
                    return CloneDuration(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_DURATION);

                case "C_DATE_TIME":
                    return CloneDateTime(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_DATE_TIME);

                case "C_DATE":
                    return CloneDate(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_DATE);

                case "C_TIME":
                    return CloneTime(o as openehr.openehr.am.archetype.constraint_model.primitive.Impl.C_TIME);

                default:
                    throw new NotImplementedException("The Visitor method 'Visit' with parameter type '" + o.GetType().ToString() + "' is not implemented.");
            }
        }