Search Results for

    Show / Hide Table of Contents

    Class RealmObjectBase

    Base for any object that can be persisted in a Realm. Models inheriting from this class will be processed at compile time by the Fody weaver. It is recommended that you instead inherit from IRealmObject and use the Realm Source Generator to generate your models.

    Inheritance
    object
    RealmObjectBase
    EmbeddedObject
    RealmObject
    Implements
    IRealmObjectBase
    INotifyPropertyChanged
    IReflectableType
    Namespace: Realms
    Assembly: Realm.dll
    Syntax
    [Preserve(AllMembers = true)]
    public abstract class RealmObjectBase : IRealmObjectBase, INotifyPropertyChanged, IReflectableType

    Properties

    | Edit this page View Source

    BacklinksCount

    Gets the number of objects referring to this one via either a to-one or to-many relationship.

    Declaration
    [IgnoreDataMember]
    public int BacklinksCount { get; }
    Property Value
    Type Description
    int

    The number of objects referring to this one.

    Remarks

    This property is not observable so the PropertyChanged event will not fire when its value changes.

    | Edit this page View Source

    DynamicApi

    Gets an object encompassing the dynamic API for this RealmObjectBase instance.

    Declaration
    [IgnoreDataMember]
    public DynamicObjectApi DynamicApi { get; }
    Property Value
    Type Description
    DynamicObjectApi

    A Realms.Dynamic instance that wraps this RealmObject.

    | Edit this page View Source

    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
    [IgnoreDataMember]
    public bool IsFrozen { get; }
    Property Value
    Type Description
    bool

    true if the object is frozen and immutable; false otherwise.

    See Also
    Freeze<T>(T)
    | Edit this page View Source

    IsManaged

    Gets a value indicating whether the object has been associated with a Realm, either at creation or via Add<T>(T, bool).

    Declaration
    [IgnoreDataMember]
    public bool IsManaged { get; }
    Property Value
    Type Description
    bool

    true if object belongs to a Realm; false if standalone.

    | Edit this page View Source

    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
    [IgnoreDataMember]
    public bool IsValid { get; }
    Property Value
    Type Description
    bool

    true if managed and part of the Realm or unmanaged; false if managed but deleted.

    | Edit this page View Source

    ObjectSchema

    Gets the ObjectSchema instance that describes how the Realm this object belongs to sees it.

    Declaration
    [IgnoreDataMember]
    public ObjectSchema? ObjectSchema { get; }
    Property Value
    Type Description
    ObjectSchema

    A collection of properties describing the underlying schema of this object.

    | Edit this page View Source

    Realm

    Gets the Realm instance this object belongs to, or null if it is unmanaged.

    Declaration
    [IgnoreDataMember]
    public Realm? Realm { get; }
    Property Value
    Type Description
    Realm

    The Realm instance this object belongs to.

    Methods

    | Edit this page View Source

    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.

    | Edit this page View Source

    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).

    | Edit this page View Source

    RaisePropertyChanged(string)

    Allows you to raise the PropertyChanged event.

    Declaration
    protected void RaisePropertyChanged(string propertyName = "")
    Parameters
    Type Name Description
    string propertyName

    The name of the property that has changed. If not specified, we'll use the caller name.

    | Edit this page View Source

    ToString()

    Returns a string that represents the current object.

    Declaration
    public override string? ToString()
    Returns
    Type Description
    string

    A string that represents the current object.

    Overrides
    object.ToString()

    Events

    | Edit this page View Source

    PropertyChanged

    Occurs when a property value changes.

    Declaration
    public event PropertyChangedEventHandler? PropertyChanged
    Event Type
    Type Description
    PropertyChangedEventHandler

    Implements

    IRealmObjectBase
    INotifyPropertyChanged
    IReflectableType

    Extension Methods

    FrozenObjectsExtensions.Freeze<T>(T)
    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2020-2024 Realm
    Generated by DocFX