• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-dotnet / 9881710012

10 Jul 2024 09:26PM UTC coverage: 81.928% (+0.6%) from 81.376%
9881710012

Pull #3644

github

59a21e
nirinchev
Prepare a debug build
Pull Request #3644: Prepare a debug build

2317 of 3019 branches covered (76.75%)

Branch coverage included in aggregate %.

9402 of 11285 relevant lines covered (83.31%)

42998.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.41
/Realm/Realm/Linq/RealmResultsProvider.cs
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2016 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
using System;
20
using System.Linq;
21
using System.Linq.Expressions;
22
using System.Reflection;
23
using Remotion.Linq.Parsing.ExpressionVisitors;
24
using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation;
25

26
namespace Realms
27
{
28
    internal class RealmResultsProvider : IQueryProvider
29
    {
30
        private readonly Realm _realm;
31
        private readonly Metadata? _metadata;
32

33
        private Metadata Metadata => _metadata ?? throw new NotSupportedException("Realm queries are not supported on collections of primitives");
4,443!
34

35
        internal RealmResultsProvider(Realm realm, Metadata? metadata)
5,607✔
36
        {
5,607✔
37
            _realm = realm;
5,607✔
38
            _metadata = metadata;
5,607✔
39
        }
5,607✔
40

41
        internal RealmResultsVisitor MakeVisitor() => new RealmResultsVisitor(_realm, Metadata);
3,346✔
42

43
        public IQueryable<T> CreateQuery<T>(Expression expression)
44
        {
1,096✔
45
            // If that line is changed, make sure to update the non-generic CreateQuery below!
46
            return new RealmResults<T>(_realm, Metadata, this, expression);
1,096✔
47
        }
1,096✔
48

49
        public IQueryable CreateQuery(Expression expression)
50
        {
1✔
51
            var elementType = TypeSystem.GetElementType(expression.Type);
1✔
52
            try
53
            {
1✔
54
                var resultsType = typeof(RealmResults<>).MakeGenericType(elementType);
1✔
55
                var ctor = resultsType.GetTypeInfo().DeclaredConstructors.Single(c => c.GetParameters().Length == 4);
4✔
56
                return (IQueryable)ctor.Invoke(new object[] { _realm, Metadata, this, expression });
1✔
57
            }
58
            catch (TargetInvocationException tie)
×
59
            {
×
60
                throw tie.InnerException ?? tie;
×
61
            }
62
        }
1✔
63

64
        public T Execute<T>(Expression expression) => (T)Execute(expression)!;
2,629✔
65

66
        public object? Execute(Expression expression)
67
        {
2,631✔
68
            expression = PartialEvaluatingExpressionVisitor.EvaluateIndependentSubtrees(expression, new EvaluatableExpressionFilter());
2,631✔
69
            var v = MakeVisitor();
2,631✔
70
            var visitResult = v.Visit(expression);
2,631✔
71
            var constExp = visitResult as ConstantExpression;
2,606✔
72
            return constExp?.Value;
2,606!
73
        }
2,606✔
74

75
        private class EvaluatableExpressionFilter : EvaluatableExpressionFilterBase
76
        {
77
        }
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc