Esempio n. 1
0
        private static void ExtractText(CObject obj, StringBuilder target)
        {
            switch (obj)
            {
            case COperator cOperator:
                ExtractTextFromOperator(cOperator, target);
                return;

            case CSequence sequence:     //CArray, CSequence
                ExtractTextFromEnumable(sequence, target);
                return;

            case CString cString:
                ExtractTextFromString(cString, target);
                return;

            case CInteger _:
            case CComment _:
            case CName _:
            case CNumber _:
                //Do nothing
                return;

            default:
                throw new NotImplementedException(obj.GetType().AssemblyQualifiedName);
            }
        }
Esempio n. 2
0
 public void ExtractText(CObject obj, StringBuilder target)
 {
     if (obj is CArray)
     {
         ExtractText((CArray)obj, target);
     }
     else if (obj is CComment)
     {
         ExtractText((CComment)obj, target);
     }
     else if (obj is CInteger)
     {
         ExtractText((CInteger)obj, target);
     }
     else if (obj is CName)
     {
         ExtractText((CName)obj, target);
     }
     else if (obj is CNumber)
     {
         ExtractText((CNumber)obj, target);
     }
     else if (obj is COperator)
     {
         ExtractText((COperator)obj, target);
     }
     else if (obj is CReal)
     {
         ExtractText((CReal)obj, target);
     }
     else if (obj is CSequence)
     {
         ExtractText((CSequence)obj, target);
     }
     else if (obj is CString)
     {
         ExtractText((CString)obj, target);
     }
     else
     {
         throw new NotImplementedException(obj.GetType().AssemblyQualifiedName);
     }
 }
Esempio n. 3
0
 private static void Write(CObject obj)
 {
     if (obj is CArray)
     {
         Write((CArray)obj);
     }
     else if (obj is CComment)
     {
         Write((CComment)obj);
     }
     else if (obj is CInteger)
     {
         Write((CInteger)obj);
     }
     else if (obj is CName)
     {
         Write((CName)obj);
     }
     else if (obj is CNumber)
     {
         Write((CNumber)obj);
     }
     else if (obj is COperator)
     {
         Write((COperator)obj);
     }
     else if (obj is CReal)
     {
         Write((CReal)obj);
     }
     else if (obj is CSequence)
     {
         Write((CSequence)obj);
     }
     else if (obj is CString)
     {
         Write((CString)obj);
     }
     else
     {
         throw new NotImplementedException(obj.GetType().AssemblyQualifiedName);
     }
 }
Esempio n. 4
0
        private string Describe(CObject op)
        {
            switch (op)
            {
            case CName name:
                return('"' + name.Name + '"');

            case CString str:
                return(str.CStringType + " -> " + str);    // needs decoding?

            case CReal real:
                return(real.ToString());

            case CInteger intg:
                return(intg.ToString());

            default: return($"=>{op.GetType().FullName}: {op}");
            }
        }
Esempio n. 5
0
        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);
                }
            }
        }