Beispiel #1
0
        public static IValue ConvertReturnValue <TRet>(TRet param)
        {
            var    type     = typeof(TRet);
            object objParam = (object)param;

            if (type == typeof(IValue))
            {
                return((IValue)param);
            }
            else if (type == typeof(string))
            {
                return(ValueFactory.Create((string)objParam));
            }
            else if (type == typeof(int))
            {
                return(ValueFactory.Create((int)objParam));
            }
            else if (type == typeof(decimal))
            {
                return(ValueFactory.Create((decimal)objParam));
            }
            else if (type == typeof(double))
            {
                return(ValueFactory.Create((decimal)(double)objParam));
            }
            else if (type == typeof(DateTime))
            {
                return(ValueFactory.Create((DateTime)objParam));
            }
            else if (type == typeof(bool))
            {
                return(ValueFactory.Create((bool)objParam));
            }
            else if (typeof(IRuntimeContextInstance).IsAssignableFrom(type))
            {
                if (objParam != null)
                {
                    return(ValueFactory.Create((IRuntimeContextInstance)objParam));
                }
                else
                {
                    return(ValueFactory.Create());
                }
            }
            else
            {
                throw new NotSupportedException("Type is not supported");
            }
        }
Beispiel #2
0
        public void Insert(IValue value, string identifier, bool canRead, bool canWrite)
        {
            var num = RegisterProperty(identifier);

            if (num == _values.Count)
            {
                _values.Add(null);
                _accessFlags.Add(new PropertyAccessFlags()
                {
                    CanRead = canRead, CanWrite = canWrite
                });
            }

            if (value == null)
            {
                value = ValueFactory.Create();
            }

            SetPropValue(num, value);
        }
Beispiel #3
0
        private static string FormatBoolean(bool p, FormatParametersList formatParameters)
        {
            if (p)
            {
                var truePresentation = formatParameters.GetParamValue(BOOLEAN_TRUE);
                if (truePresentation != null)
                {
                    return(truePresentation);
                }
            }
            else
            {
                var falsePresentation = formatParameters.GetParamValue(BOOLEAN_FALSE);
                if (falsePresentation != null)
                {
                    return(falsePresentation);
                }
            }

            return(ValueFactory.Create(p).AsString());
        }
        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);
            }
        }
        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);
        }