예제 #1
0
        private static void Execute(T item,
                                    Action <RealmObject> objectHandler,
                                    Action <PrimitiveValue> primitiveHandler,
                                    Action <string> stringHandler,
                                    Action <byte[]> binaryHandler)
        {
            switch (_argumentType)
            {
            case PropertyType.Object | PropertyType.Nullable:
                objectHandler(Operator.Convert <T, RealmObject>(item));
                break;

            case PropertyType.String:
            case PropertyType.String | PropertyType.Nullable:
                stringHandler(Operator.Convert <T, string>(item));
                break;

            case PropertyType.Data:
            case PropertyType.Data | PropertyType.Nullable:
                binaryHandler(Operator.Convert <T, byte[]>(item));
                break;

            default:
                primitiveHandler(PrimitiveValue.Create(item, _argumentType));
                break;
            }
        }
예제 #2
0
        public override int IndexOf(T value)
        {
            switch (_argumentType)
            {
            case PropertyType.Object | PropertyType.Nullable:
                Argument.NotNull(value, nameof(value));

                var obj = Operator.Convert <T, RealmObject>(value);
                if (!obj.IsManaged)
                {
                    throw new ArgumentException("Value does not belong to a realm", nameof(value));
                }

                return(_listHandle.Find(obj.ObjectHandle));

            case PropertyType.String:
            case PropertyType.String | PropertyType.Nullable:
                return(_listHandle.Find(Operator.Convert <T, string>(value)));

            case PropertyType.Data:
            case PropertyType.Data | PropertyType.Nullable:
                return(_listHandle.Find(Operator.Convert <T, byte[]>(value)));

            default:
                return(_listHandle.Find(PrimitiveValue.Create(value, _argumentType)));
            }
        }