Exemplo n.º 1
0
        public void ShowProperties(IRuntimeContextInstance context)
        {
            var propsCount = context.GetPropCount();

            for (int i = 0; i < propsCount; i++)
            {
                var propNum  = i;
                var propName = context.GetPropName(propNum);

                IVariable value;

                try
                {
                    value = Variable.Create(context.GetPropValue(propNum), propName);
                }
                catch (Exception e)
                {
                    value = Variable.Create(ValueFactory.Create(e.Message), propName);
                }

                _children.Add(value);
            }
        }
Exemplo n.º 2
0
 public bool AsBoolean()
 {
     return(ValueFactory.Parse(_value, DataType.Boolean).AsBoolean());
 }
Exemplo n.º 3
0
 public DateTime AsDate()
 {
     return(ValueFactory.Parse(_value, DataType.Date).AsDate());
 }
Exemplo n.º 4
0
 public decimal AsNumber()
 {
     return(ValueFactory.Parse(_value, DataType.Number).AsNumber());
 }
Exemplo n.º 5
0
        public static IValue Parse(string presentation, DataType type)
        {
            IValue result;

            switch (type)
            {
            case DataType.Boolean:

                if (String.Compare(presentation, "истина", StringComparison.OrdinalIgnoreCase) == 0 ||
                    String.Compare(presentation, "true", StringComparison.OrdinalIgnoreCase) == 0 ||
                    String.Compare(presentation, "да", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    result = ValueFactory.Create(true);
                }
                else if (String.Compare(presentation, "ложь", StringComparison.OrdinalIgnoreCase) == 0 ||
                         String.Compare(presentation, "false", StringComparison.OrdinalIgnoreCase) == 0 ||
                         String.Compare(presentation, "нет", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    result = ValueFactory.Create(false);
                }
                else
                {
                    throw RuntimeException.ConvertToBooleanException();
                }

                break;

            case DataType.Date:
                string format;
                if (presentation.Length == 14)
                {
                    format = "yyyyMMddHHmmss";
                }
                else if (presentation.Length == 8)
                {
                    format = "yyyyMMdd";
                }
                else if (presentation.Length == 12)
                {
                    format = "yyyyMMddHHmm";
                }
                else
                {
                    throw RuntimeException.ConvertToDateException();
                }

                if (presentation == "00000000" ||
                    presentation == "000000000000" ||
                    presentation == "00000000000000")
                {
                    result = ValueFactory.Create(new DateTime());
                }
                else
                {
                    try
                    {
                        result = ValueFactory.Create(DateTime.ParseExact(presentation, format, System.Globalization.CultureInfo.InvariantCulture));
                    }
                    catch (FormatException)
                    {
                        throw RuntimeException.ConvertToDateException();
                    }
                }

                break;

            case DataType.Number:
                var numInfo  = NumberFormatInfo.InvariantInfo;
                var numStyle = NumberStyles.AllowDecimalPoint
                               | NumberStyles.AllowLeadingSign
                               | NumberStyles.AllowLeadingWhite
                               | NumberStyles.AllowTrailingWhite;

                try
                {
                    result = ValueFactory.Create(Decimal.Parse(presentation, numStyle, numInfo));
                }
                catch (FormatException)
                {
                    throw RuntimeException.ConvertToNumberException();
                }
                break;

            case DataType.String:
                result = ValueFactory.Create(presentation);
                break;

            case DataType.Undefined:
                result = ValueFactory.Create();
                break;

            case DataType.GenericValue:
                if (string.Compare(presentation, "null", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    result = ValueFactory.CreateNullValue();
                }
                else
                {
                    throw new NotImplementedException("constant type is not supported");
                }

                break;

            default:
                throw new NotImplementedException("constant type is not supported");
            }

            return(result);
        }