Beispiel #1
0
        public static object ToObject(FLValue *value)
        {
            if (value == null)
            {
                return(null);
            }

            switch (Native.FLValue_GetType(value))
            {
            case FLValueType.Array:
            {
                var arr    = Native.FLValue_AsArray(value);
                var retVal = new object[Native.FLArray_Count(arr)];
                var i      = default(FLArrayIterator);
                Native.FLArrayIterator_Begin(arr, &i);
                int pos = 0;
                do
                {
                    retVal[pos++] = ToObject(Native.FLArrayIterator_GetValue(&i));
                } while (Native.FLArrayIterator_Next(&i));

                return(retVal);
            }

            case FLValueType.Boolean:
                return(Native.FLValue_AsBool(value));

            case FLValueType.Data:
                return(Native.FLValue_AsData(value));

            case FLValueType.Dict:
            {
                var dict   = Native.FLValue_AsDict(value);
                var retVal = new Dictionary <string, object>((int)Native.FLDict_Count(dict));
                var i      = default(FLDictIterator);
                Native.FLDictIterator_Begin(dict, &i);
                do
                {
                    var    rawKey = Native.FLDictIterator_GetKey(&i);
                    string key    = Native.FLValue_AsString(rawKey);
                    if (key == null)
                    {
                        break;
                    }

                    retVal[key] = ToObject(Native.FLDictIterator_GetValue(&i));
                } while (Native.FLDictIterator_Next(&i));

                return(retVal);
            }

            case FLValueType.Null:
                return(null);

            case FLValueType.Number:
                if (Native.FLValue_IsInteger(value))
                {
                    if (Native.FLValue_IsUnsigned(value))
                    {
                        return(Native.FLValue_AsUnsigned(value));
                    }

                    return(Native.FLValue_AsInt(value));
                }
                else if (Native.FLValue_IsDouble(value))
                {
                    return(Native.FLValue_AsDouble(value));
                }

                return(Native.FLValue_AsFloat(value));

            case FLValueType.String:
                return(Native.FLValue_AsString(value));

            default:
                return(null);
            }
        }
 public void FLArrayIterator_Begin(FLArray *array, FLArrayIterator *i) => Native.FLArrayIterator_Begin(array, i);