Ejemplo n.º 1
0
        public string TryEvaluateToString()
        {
            ICanEvaluateToString floater = this as ICanEvaluateToString;

            if (floater == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "{0} can't be evaluated to string!",
                              GetType().Name));
            }
            return(floater.EvaluateToString());
        }
Ejemplo n.º 2
0
        public override string EvaluateToString()
        {
            List <object> arguments = new List <object>();

            foreach (LispOperator <TBb> @op in Children.Skip(1))
            {
                ICanEvaluateToBool canEvaluateToBool = @op as ICanEvaluateToBool;
                if (canEvaluateToBool != null)
                {
                    arguments.Add(canEvaluateToBool.EvaluateToBool());
                    continue;
                }

                ICanEvaluateToFloat canEvaluateToFloat = @op as ICanEvaluateToFloat;
                if (canEvaluateToFloat != null)
                {
                    arguments.Add(canEvaluateToFloat.EvaluateToFloat());
                    continue;
                }

                ICanEvaluateToString canEvaluateToString = @op as ICanEvaluateToString;
                if (canEvaluateToString != null)
                {
                    arguments.Add(canEvaluateToString.EvaluateToString());
                    continue;
                }

                throw new InvalidOperationException(string.Format("Argument can't be evaluated to string: {0}", @op));
            }

            string formatString = Children.First().TryEvaluateToString();

            try
            {
                return(string.Format(formatString, arguments.ToArray()));
            }
            catch
            {
                return("BAD FORMAT: " + formatString);
            }
        }