public JObject getJObjectForSerialization()
        {
            JObject jObject = new JObject();

            jObject.Add(new JProperty("key", _key));
            jObject.Add(new JProperty("type", _type));

            if (_value.GetType() == typeof(StringData))
            {
                StringData stringData = (StringData)_value;
                jObject.Add(new JProperty("value", stringData.value));
            }
            if (_value.GetType() == typeof(BoolData))
            {
                BoolData boolData = (BoolData)_value;
                jObject.Add(new JProperty("value", boolData.value));
            }
            if (_value.GetType() == typeof(NumberData))
            {
                NumberData numberData = (NumberData)_value;
                jObject.Add(new JProperty("value", numberData.value));
            }
            if (_value.GetType() == typeof(ArrayData))
            {
                ArrayData arrayData = (ArrayData)_value;
                jObject.Add(new JProperty("value", arrayData.ToString()));
            }

            jObject.Add(new JProperty("readonly", _isReadonly));
            jObject.Add(new JProperty("writeonly", _isWriteonly));
            jObject.Add(new JProperty("allowedValues", _allowedValues));
            jObject.Add(new JProperty("bindTo", null));
            return(jObject);
        }
Exemplo n.º 2
0
        public bool compare(SimCapiData simCapiData)
        {
            bool equal = false;

            // Edge case for Number,
            // The string compare dosent work for numbers as the strings can be different but the number is the same
            // "8" != "8.0" but they are the same float value
            // so we have to convert the string to a float then do the compare
            if (GetType() == typeof(NumberData))
            {
                NumberData numberA = (NumberData)this;
                float?     numberB = simCapiData.getNumber();

                if (numberB == null)
                {
                    return(false);
                }

                equal = numberA.value == numberB.Value;

                //SimCapiConsole.log("NUMB |" + numberA.value.ToString() + "|" + numberB.Value.ToString() + "| equal: " + equal.ToString());
                return(equal);
            }

            string a = ToString();
            string b = simCapiData.ToString();

            equal = a == b;
            //SimCapiConsole.log("|" + a + "|" + b + "| equal: " + equal.ToString());

            return(equal);
        }
        public void setValueWithData(SimCapiData data)
        {
            switch (_type)
            {
            case SimCapiValueType.NUMBER:
            {
                NumberData numberData = (NumberData)_value;

                float?value = data.getNumber();

                if (value == null)
                {
                    SimCapiConsole.log("Cannot set " + _type.ToString() + " with " + data.GetType().ToString());
                }
                else
                {
                    numberData.value = value.Value;
                }

                break;
            }

            case SimCapiValueType.ARRAY:
            {
                ArrayData arrayData = (ArrayData)_value;

                string[] value = data.getStringArray();

                if (value == null)
                {
                    SimCapiConsole.log("Cannot set " + _type.ToString() + " with " + data.GetType().ToString());
                }
                else
                {
                    arrayData.value = value;
                }

                break;
            }

            case SimCapiValueType.BOOLEAN:
            {
                BoolData boolData = (BoolData)_value;

                bool?value = data.getBool();

                if (value == null)
                {
                    SimCapiConsole.log("Cannot set " + _type.ToString() + " with " + data.GetType().ToString());
                }
                else
                {
                    boolData.value = value.Value;
                }

                break;
            }

            case SimCapiValueType.STRING:
            case SimCapiValueType.ENUM:
            case SimCapiValueType.MATH_EXPR:
            case SimCapiValueType.ARRAY_POINT:
            {
                StringData stringData = (StringData)_value;
                stringData.value = data.ToString();
                break;
            }
            }
        }