Esempio n. 1
0
        private static async Task <object> ToSimpleObject(IBifoqlIndexInternal index)
        {
            // TODO - index lookup probably should return IBifoqlObject, not object.
            var resultWithZeroArgs = await index.Lookup(IndexArgumentList.CreateEmpty());

            if (resultWithZeroArgs is IBifoqlObject)
            {
                return(await((IBifoqlObject)resultWithZeroArgs).ToSimpleObject());
            }
            else
            {
                return(resultWithZeroArgs);
            }
        }
Esempio n. 2
0
        private static Func <Task <IBifoqlObject> > GetDefaultValueFromIndexFunc(object o)
        {
            if (o is IBifoqlObject)
            {
                return(GetDefaultValueFromIndexFunc((IBifoqlObject)o));
            }

            // For a key, we want to get the default value only if the thing before it is an index; it doesn't
            // make sense to look up keys on an index after all.
            if (o is IBifoqlIndex || o is IBifoqlIndexSync)
            {
                // First, is there a default value?
                if (o is IDefaultValue)
                {
                    var defaultValue = ((IDefaultValue)o).GetDefaultValue();
                    if (defaultValue != null)
                    {
                        return(async() => (await defaultValue).ToBifoqlObject());
                    }
                }
                else if (o is IDefaultValueSync)
                {
                    var defaultValue = ((IDefaultValueSync)o).GetDefaultValue();
                    if (defaultValue != null)
                    {
                        return(() => Task.FromResult(defaultValue.ToBifoqlObject()));
                    }
                }
                else if (o is IBifoqlIndex)
                {
                    return(async() => {
                        var value = await((IBifoqlIndex)o).Lookup(IndexArgumentList.CreateEmpty());
                        return value.ToBifoqlObject();
                    });
                }
                else if (o is IBifoqlIndexSync)
                {
                    return(() => {
                        var value = ((IBifoqlIndexSync)o).Lookup(IndexArgumentList.CreateEmpty());
                        return Task.FromResult(value.ToBifoqlObject());
                    });
                }

                throw new Exception("UNEXPECTED");
            }

            return(null);
        }
Esempio n. 3
0
        private static Func <Task <IBifoqlObject> > GetDefaultValueFromIndexFunc(IBifoqlObject o)
        {
            if (o is IBifoqlIndexInternal)
            {
                if (o is IBifoqlHasDefaultValue)
                {
                    return(((IBifoqlHasDefaultValue)o).GetDefaultValue());
                }

                // Pass zero arguments to the index.
                return(async() => {
                    var obj = await((IBifoqlIndexInternal)o).Lookup(IndexArgumentList.CreateEmpty());
                    return obj.ToBifoqlObject();
                });
            }

            return(null);
        }