Example #1
0
        private Expression GetObjectAtIndex(int index, ResultsHandle rh, string methodName)
        {
            try
            {
                var val = rh.GetValueAtIndex(index, _realm);
                return(Expression.Constant(val.AsRealmObject()));
            }
            catch (ArgumentOutOfRangeException ex)
            {
                if (methodName.EndsWith("OrDefault", StringComparison.OrdinalIgnoreCase))
                {
                    // For First/Last/Single/ElemetAtOrDefault - ignore
                    return(Expression.Constant(null));
                }

                if (methodName == nameof(Queryable.ElementAt))
                {
                    // ElementAt should rethrow the ArgumentOutOfRangeException.
                    throw;
                }

                // All the rest should throw an InvalidOperationException.
                throw new InvalidOperationException("Sequence contains no matching element", ex);
            }
        }
Example #2
0
 protected override T GetValueAtIndex(int index) => ResultsHandle.GetValueAtIndex(index, Realm).As <T>();