Class CollectionNotificationsExtensions
A set of extensions methods exposing notification-related functionality over collections.
Namespace: Realms
Assembly: Realm.dll
Syntax
public static class CollectionNotificationsExtensions
Methods
| Improve this Doc View SourceAsRealmCollection<T>(IList<T>)
A convenience method that casts IList<T> to IRealmCollection<T> which implements INotifyCollectionChanged.
Declaration
public static IRealmCollection<T> AsRealmCollection<T>(this IList<T> list)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The IList<T> to observe for changes. |
Returns
Type | Description |
---|---|
IRealmCollection<T> | The collection, implementing INotifyCollectionChanged. |
Type Parameters
Name | Description |
---|---|
T | Type of the objects in the list. |
See Also
| Improve this Doc View SourceAsRealmCollection<T>(IQueryable<T>)
A convenience method that casts IQueryable<T> to IRealmCollection<T> which implements INotifyCollectionChanged.
Declaration
public static IRealmCollection<T> AsRealmCollection<T>(this IQueryable<T> results)
where T : RealmObject
Parameters
Type | Name | Description |
---|---|---|
IQueryable<T> | results | The IQueryable<T> to observe for changes. |
Returns
Type | Description |
---|---|
IRealmCollection<T> | The collection, implementing INotifyCollectionChanged. |
Type Parameters
Name | Description |
---|---|
T | Type of the RealmObject in the results. |
See Also
| Improve this Doc View SourceFilter<T>(IQueryable<T>, String)
Apply an NSPredicate-based filter over a collection. It can be used to create more complex queries, that are currently unsupported by the LINQ provider and supports SORT and DISTINCT clauses in addition to filtering.
Declaration
public static IQueryable<T> Filter<T>(this IQueryable<T> results, string predicate)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<T> | results | A Queryable collection, obtained by calling All<T>(). |
String | predicate | The predicate that will be applied. |
Returns
Type | Description |
---|---|
IQueryable<T> | A queryable observable collection of objects that match the predicate. |
Type Parameters
Name | Description |
---|---|
T | The type of the objects that will be filtered. |
Remarks
This method can be used in combination with LINQ filtering, but it is strongly recommended
to avoid combining it if a SORT
clause appears in the predicate.
If you're not going to apply additional filters, it's recommended to use AsRealmCollection<T>(IQueryable<T>) after applying the predicate.
Examples
var results1 = realm.All<Foo>("Bar.IntValue > 0");
var results2 = realm.All<Foo>("Bar.IntValue > 0 SORT(Bar.IntValue ASC Bar.StringValue DESC)");
var results3 = realm.All<Foo>("Bar.IntValue > 0 SORT(Bar.IntValue ASC Bar.StringValue DESC) DISTINCT(Bar.IntValue)");
See Also
| Improve this Doc View SourceMove<T>(IList<T>, T, Int32)
Move the specified item to a new position within the list.
Declaration
public static void Move<T>(this IList<T> list, T item, int index)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list where the move should occur. |
T | item | The item that will be moved. |
Int32 | index | The new position to which the item will be moved. |
Type Parameters
Name | Description |
---|---|
T | Type of the objects in the list. |
Remarks
This extension method will work for standalone lists as well by calling Remove(T) and then Insert(Int32, T).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if the index is less than 0 or greater than Count - 1. |
Move<T>(IList<T>, Int32, Int32)
Move the specified item to a new position within the list.
Declaration
public static void Move<T>(this IList<T> list, int from, int to)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The list where the move should occur. |
Int32 | from | The index of the item that will be moved. |
Int32 | to | The new position to which the item will be moved. |
Type Parameters
Name | Description |
---|---|
T | Type of the objects in the list. |
Remarks
This extension method will work for standalone lists as well by calling RemoveAt(Int32) and then Insert(Int32, T).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if the index is less than 0 or greater than Count - 1. |
SubscribeForNotifications<T>(IList<T>, NotificationCallbackDelegate<T>)
A convenience method that casts IList<T> to IRealmCollection<T> and subscribes for change notifications.
Declaration
public static IDisposable SubscribeForNotifications<T>(this IList<T> list, NotificationCallbackDelegate<T> callback)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The IList<T> to observe for changes. |
NotificationCallbackDelegate<T> | callback | The callback to be invoked with the updated IRealmCollection<T>. |
Returns
Type | Description |
---|---|
IDisposable | A subscription token. It must be kept alive for as long as you want to receive change notifications. To stop receiving notifications, call Dispose(). |
Type Parameters
Name | Description |
---|---|
T | Type of the objects in the list. |
See Also
| Improve this Doc View SourceSubscribeForNotifications<T>(IQueryable<T>, NotificationCallbackDelegate<T>)
A convenience method that casts IQueryable<T> to IRealmCollection<T> and subscribes for change notifications.
Declaration
public static IDisposable SubscribeForNotifications<T>(this IQueryable<T> results, NotificationCallbackDelegate<T> callback)
where T : RealmObject
Parameters
Type | Name | Description |
---|---|---|
IQueryable<T> | results | The IQueryable<T> to observe for changes. |
NotificationCallbackDelegate<T> | callback | The callback to be invoked with the updated IRealmCollection<T>. |
Returns
Type | Description |
---|---|
IDisposable | A subscription token. It must be kept alive for as long as you want to receive change notifications. To stop receiving notifications, call Dispose(). |
Type Parameters
Name | Description |
---|---|
T | Type of the RealmObject in the results. |