Realm Xamarin  v0.78.0
Realm for Xamarin
Classes | Public Member Functions | Public Attributes | List of all members
RealmResults< T > Class Template Reference

Iterable, sortable collection of one kind of RealmObject resulting from Realm.All() or from a LINQ query expression. More...

Inherits IOrderedQueryable< T >, RealmResultsNativeHelper.Interface, and IRealmResults.

Classes

class  ChangeSet
 A ChangeSet describes the changes inside a RealmResults<T> since the last time the notification callback was invoked. More...
 

Public Member Functions

int Count ()
 Fast count all objects of a given class, or in a RealmResults after casting. More...
 
IEnumerator< T > GetEnumerator ()
 Standard method from interface IEnumerable allows the RealmResults to be used in a foreach or ToList(). More...
 
delegate void NotificationCallback (RealmResults< T > sender, ChangeSet changes, Exception error)
 A callback that will be invoked each time the contents of a RealmResults<T> have changed. More...
 
IDisposable SubscribeForNotifications (NotificationCallback callback)
 Register a callback to be invoked each time this RealmResults<T> changes. More...
 

Public Attributes

Schema.ObjectSchema ObjectSchema => _targetMetadata.Schema
 The Schema.ObjectSchema that describes the type of item this collection can contain. More...
 

Detailed Description

Iterable, sortable collection of one kind of RealmObject resulting from Realm.All() or from a LINQ query expression.

Implements IOrderedQueryable.
You can sort efficiently using the standard LINQ operators OrderBy or OrderByDescending followed by any number of ThenBy or ThenByDescending.

Template Parameters
TType of the RealmObject which is being returned.

Member Function Documentation

§ Count()

int Count ( )

Fast count all objects of a given class, or in a RealmResults after casting.

Resolves to this method instead of the LINQ static extension Count<T>(this IEnumerable<T>), when used directly on Realm.All.
if someone CASTS a RealmResults<T> variable from a Where call to a RealmResults<T> they change its compile-time type from IQueryable<blah> (which invokes LINQ) to RealmResults<T> and thus ends up here.

Returns
Count of all objects in a class or in the results of a search, without instantiating them.

References RealmResults< T >.ObjectSchema.

§ GetEnumerator()

IEnumerator<T> GetEnumerator ( )

Standard method from interface IEnumerable allows the RealmResults to be used in a foreach or ToList().

Returns
An IEnumerator which will iterate through found Realm persistent objects.

References RealmResults< T >.ObjectSchema.

§ NotificationCallback()

delegate void NotificationCallback ( RealmResults< T >  sender,
ChangeSet  changes,
Exception  error 
)

A callback that will be invoked each time the contents of a RealmResults<T> have changed.

Parameters
senderThe RealmResults<T> being monitored for changes.
changesThe ChangeSet describing the changes to a RealmResults<T>, or null if an error occured.
errorAn exception that might have occured while asynchronously monitoring a RealmResults<T> for changes, or null if no errors occured.

Referenced by RealmResults< T >.SubscribeForNotifications().

§ SubscribeForNotifications()

IDisposable SubscribeForNotifications ( NotificationCallback  callback)

Register a callback to be invoked each time this RealmResults<T> changes.

The callback will be asynchronously invoked with the initial RealmResults<T>, and then called again after each write transaction which changes either any of the objects in the collection, or which objects are in the collection. The changes parameter will be null the first time the callback is invoked with the initial results. For each call after that, it will contain information about which rows in the results were added, removed or modified.

If a write transaction did not modify any objects in this RealmResults<T>, the callback is not invoked at all. If an error occurs the callback will be invoked with null for the sender parameter and a non-null error. Currently the only errors that can occur are when opening the Realms.Realm on the background worker thread.

At the time when the block is called, the RealmResults<T> object will be fully evaluated and up-to-date, and as long as you do not perform a write transaction on the same thread or explicitly call Realm.Refresh, accessing it will never perform blocking work.

Notifications are delivered via the standard event loop, and so can't be delivered while the event loop is blocked by other activity. When notifications can't be delivered instantly, multiple notifications may be coalesced into a single notification. This can include the notification with the initial collection.

Parameters
callbackThe callback to be invoked with the updated RealmResults<T>.
Returns
A subscription token. It must be kept alive for as long as you want to receive change notifications. To stop receiving notifications, call IDisposable.Dispose.

References RealmResults< T >.NotificationCallback(), and RealmResults< T >.ObjectSchema.

Member Data Documentation

§ ObjectSchema

Schema.ObjectSchema ObjectSchema => _targetMetadata.Schema

The Schema.ObjectSchema that describes the type of item this collection can contain.

Referenced by RealmResults< T >.Count(), RealmResults< T >.GetEnumerator(), and RealmResults< T >.SubscribeForNotifications().