• 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

89.8
/Realm/Realm/Dynamic/MetaRealmList.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.Dynamic;
21
using System.Linq;
22
using System.Linq.Expressions;
23

24
namespace Realms.Dynamic
25
{
26
    internal class MetaRealmList : DynamicMetaObject
27
    {
28
        internal MetaRealmList(Expression expression, object value) : base(expression, BindingRestrictions.Empty, value)
66✔
29
        {
66✔
30
        }
66✔
31

32
        public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
33
        {
6✔
34
            var limitedSelf = Expression;
6✔
35
            if (limitedSelf.Type != LimitType)
6✔
36
            {
6✔
37
                limitedSelf = Expression.Convert(limitedSelf, LimitType);
6✔
38
            }
6✔
39

40
            var indexer = LimitType.GetProperty("Item") ?? throw new NotSupportedException("Could not find the Item indexer for this list.");
6!
41
            var indexerGetValue = indexer.GetGetMethod() ?? throw new NotSupportedException("Could not find the Item indexer getter for this list.");
6!
42
            Expression expression = Expression.Call(limitedSelf, indexerGetValue, indexes.Select(i => i.Expression));
12✔
43
            if (binder.ReturnType != expression.Type)
6✔
44
            {
6✔
45
                expression = Expression.Convert(expression, binder.ReturnType);
6✔
46
            }
6✔
47

48
            return new DynamicMetaObject(expression, BindingRestrictions.GetTypeRestriction(Expression, LimitType));
6✔
49
        }
6✔
50

51
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
52
        {
2✔
53
            if (Value is IRealmCollection<IEmbeddedObject>)
2!
54
            {
2✔
55
                throw new NotSupportedException("Can't set embedded objects directly. Instead use Realm.DynamicApi.SetEmbeddedObjectInList.");
2✔
56
            }
57

58
            return base.BindSetIndex(binder, indexes, value);
×
59
        }
×
60

61
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
62
        {
28✔
63
            if (Value is IRealmCollection<IEmbeddedObject>)
28✔
64
            {
8✔
65
                switch (binder.Name)
8✔
66
                {
67
                    case "Add":
68
                        throw new NotSupportedException("Can't add embedded objects directly. Instead use Realm.DynamicApi.AddEmbeddedObjectToList.");
2✔
69
                    case "Insert":
70
                        throw new NotSupportedException("Can't insert embedded objects directly. Instead use Realm.DynamicApi.InsertEmbeddedObjectInList.");
2✔
71
                }
72
            }
4✔
73

74
            return base.BindInvokeMember(binder, args);
24✔
75
        }
24✔
76
    }
77
}
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