Class RealmObjectBase
Base for any object that can be persisted in a Realm.
Namespace: Realms
Assembly: Realm.dll
Syntax
[Preserve(AllMembers = true, Conditional = false)]
[Serializable]
public abstract class RealmObjectBase : INotifyPropertyChanged, IThreadConfined, NotificationsHelper.INotifiable, IReflectableType
Properties
| Improve this Doc View SourceBacklinksCount
Gets the number of objects referring to this one via either a to-one or to-many relationship.
Declaration
public int BacklinksCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Remarks
This property is not observable so the PropertyChanged event will not fire when its value changes.
IsFrozen
Gets a value indicating whether this object is frozen. Frozen objects are immutable and will not update when writes are made to the Realm. Unlike live objects, frozen objects can be used across threads.
Declaration
public bool IsFrozen { get; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
IsManaged
Gets a value indicating whether the object has been associated with a Realm, either at creation or via Add<T>(T, Boolean).
Declaration
public bool IsManaged { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
IsValid
Gets a value indicating whether this object is managed and represents a row in the database. If a managed object has been removed from the Realm, it is no longer valid and accessing properties on it will throw an exception. Unmanaged objects are always considered valid.
Declaration
public bool IsValid { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
ObjectSchema
Gets the ObjectSchema instance that describes how the Realm this object belongs to sees it.
Declaration
public ObjectSchema ObjectSchema { get; }
Property Value
Type | Description |
---|---|
ObjectSchema | A collection of properties describing the underlying schema of this object. |
Realm
Gets the Realm instance this object belongs to, or null
if it is unmanaged.
Declaration
public Realm Realm { get; }
Property Value
Type | Description |
---|---|
Realm | The Realm instance this object belongs to. |
Methods
| Improve this Doc View SourceFinalize()
Finalizes an instance of the RealmObjectBase class.
Declaration
protected void Finalize()
GetBacklinks(String, String)
Returns all the objects that link to this object in the specified relationship.
Declaration
public IQueryable<dynamic> GetBacklinks(string objectType, string property)
Parameters
Type | Name | Description |
---|---|---|
String | objectType | The type of the object that is on the other end of the relationship. |
String | property | The property that is on the other end of the relationship. |
Returns
Type | Description |
---|---|
IQueryable<Object> | A queryable collection containing all objects of |
GetBacklinks<T>(String)
Declaration
protected IQueryable<T> GetBacklinks<T>(string propertyName)
where T : RealmObjectBase
Parameters
Type | Name | Description |
---|---|---|
String | propertyName |
Returns
Type | Description |
---|---|
IQueryable<T> |
Type Parameters
Name | Description |
---|---|
T |
GetListValue<T>(String)
Declaration
protected IList<T> GetListValue<T>(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName |
Returns
Type | Description |
---|---|
IList<T> |
Type Parameters
Name | Description |
---|---|
T |
GetSetValue<T>(String)
Declaration
protected ISet<T> GetSetValue<T>(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName |
Returns
Type | Description |
---|---|
ISet<T> |
Type Parameters
Name | Description |
---|---|
T |
GetTypeInfo()
Declaration
public TypeInfo GetTypeInfo()
Returns
Type | Description |
---|---|
TypeInfo |
GetValue(String)
Declaration
protected RealmValue GetValue(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName |
Returns
Type | Description |
---|---|
RealmValue |
OnManaged()
Called when the object has been managed by a Realm.
Declaration
protected virtual void OnManaged()
Remarks
This method will be called either when a managed object is materialized or when an unmanaged object has been added to the Realm. It can be useful for providing some initialization logic as when the constructor is invoked, it is not yet clear whether the object is managed or not.
OnPropertyChanged(String)
Called when a property has changed on this class.
Declaration
protected virtual void OnPropertyChanged(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | The name of the property. |
Remarks
For this method to be called, you need to have first subscribed to PropertyChanged. This can be used to react to changes to the current object, e.g. raising PropertyChanged for computed properties.
Examples
class MyClass : RealmObject
{
public int StatusCodeRaw { get; set; }
public StatusCodeEnum StatusCode => (StatusCodeEnum)StatusCodeRaw;
protected override void OnPropertyChanged(string propertyName)
{
if (propertyName == nameof(StatusCodeRaw))
{
RaisePropertyChanged(nameof(StatusCode));
}
}
}
Here, we have a computed property that depends on a persisted one. In order to notify any PropertyChanged
subscribers that StatusCode
has changed, we override OnPropertyChanged(String) and
raise PropertyChanged manually by calling RaisePropertyChanged(String).
RaisePropertyChanged(String)
Allows you to raise the PropertyChanged event.
Declaration
protected void RaisePropertyChanged(string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | The name of the property that has changed. If not specified, we'll use the caller name. |
SetValue(String, RealmValue)
Declaration
protected void SetValue(string propertyName, RealmValue val)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | |
RealmValue | val |
SetValueUnique(String, RealmValue)
Declaration
protected void SetValueUnique(string propertyName, RealmValue val)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | |
RealmValue | val |
Events
| Improve this Doc View SourcePropertyChanged
Occurs when a property value changes.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type | Description |
---|---|
PropertyChangedEventHandler |