Realm Xamarin  v0.80.0
Realm for Xamarin
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
RealmConfiguration Class Reference

Realm configuration specifying settings that affect the Realm's behavior. More...

Public Member Functions

 RealmConfiguration (string optionalPath=null, bool shouldDeleteIfMigrationNeeded=false)
 Initializes a new instance of the RealmConfiguration class. More...
 
RealmConfiguration ConfigWithPath (string newConfigPath)
 Clone method allowing you to override or customize the current path. More...
 
override bool Equals (object obj)
 Generic override determines whether the specified System.Object is equal to the current Realms.RealmConfiguration. More...
 
bool Equals (RealmConfiguration rhs)
 Determines whether the specified RealmConfiguration is equal to the current RealmConfiguration. More...
 
override int GetHashCode ()
 Serves as a hash function for a RealmConfiguration based on its path. More...
 
delegate void MigrationCallbackDelegate (Migration migration, ulong oldSchemaVersion)
 In order to handle manual migrations, you need to supply one of these to your RealmConfiguration. It will be called with a Migration instance containing the pre- and the post-migration realm. You should make sure that the NewRealm property on it contains a database that is up to date when returning. The oldSchemaVersion parameter will tell you which version the user is migrating from. They should always be migrating to the current version. More...
 

Static Public Member Functions

static string PathToRealm (string optionalPath=null)
 Utility to build a path in which a realm will be created so can consistently use filenames and relative paths. More...
 

Public Attributes

bool ReadOnly
 Flag to indicate Realm is opened readonly so can open from locked locations such as bundled with an application. More...
 
readonly bool ShouldDeleteIfMigrationNeeded
 Flag indicating that the database will be deleted if the schema mismatches the one in the code. Use this when debugging and developing your app but never release it with this flag set to true. More...
 

Static Public Attributes

static string DefaultRealmName => "default.realm"
 Gets the filename to be combined with the platform-specific document directory. More...
 

Properties

string DatabasePath [get]
 Gets the full path of the realms opened with this configuration, may be overriden by passing in a separate name. More...
 
static RealmConfiguration DefaultConfiguration [get, set]
 Gets or sets the configuration that is used when creating a new Realm without specifying a configuration. More...
 
byte [] EncryptionKey [get, set]
 Gets or sets the key, used to encrypt the entire Realm. Once set, must be specified each time file is used. More...
 
MigrationCallbackDelegate MigrationCallback [get, set]
 Gets or sets the migration callback. More...
 
Type [] ObjectClasses [get, set]
 Gets or sets the list of classes persisted in a Realm opened with this configuration. More...
 
ulong SchemaVersion [get, set]
 Gets or sets a number, indicating the version of the schema. Can be used to arbitrarily distinguish between schemas even if they have the same objects and properties. More...
 

Detailed Description

Realm configuration specifying settings that affect the Realm's behavior.

Main role is generating a canonical path from whatever absolute, relative subdirectory or just filename the user supplies.

Constructor & Destructor Documentation

§ RealmConfiguration()

RealmConfiguration ( string  optionalPath = null,
bool  shouldDeleteIfMigrationNeeded = false 
)

Initializes a new instance of the RealmConfiguration class.

Parameters
optionalPathPath to the realm, must be a valid full path for the current platform, relative subdirectory, or just filename.
shouldDeleteIfMigrationNeededOptional Flag mainly to help with temp databases and testing, indicates content can be abandoned when you change the schema.

References RealmConfiguration.DatabasePath, and RealmConfiguration.PathToRealm().

Referenced by RealmConfiguration.ConfigWithPath().

Member Function Documentation

§ ConfigWithPath()

RealmConfiguration ConfigWithPath ( string  newConfigPath)

Clone method allowing you to override or customize the current path.

Returns
An object with a fully-specified, canonical path.
Parameters
newConfigPathPath to the realm, must be a valid full path for the current platform, relative subdirectory, or just filename.

References RealmConfiguration.DatabasePath, and RealmConfiguration.RealmConfiguration().

Referenced by Realm.DeleteRealm(), and Realm.GetInstance().

§ Equals() [1/2]

override bool Equals ( object  obj)

Generic override determines whether the specified System.Object is equal to the current Realms.RealmConfiguration.

Parameters
objThe System.Object to compare with the current Realms.RealmConfiguration.
Returns
true if the specified System.Object is equal to the current Realms.RealmConfiguration; otherwise, false.

Referenced by Realm.Equals().

§ Equals() [2/2]

bool Equals ( RealmConfiguration  rhs)

Determines whether the specified RealmConfiguration is equal to the current RealmConfiguration.

Parameters
rhsThe System.Object to compare with the current RealmConfiguration.
Returns
true if the specified System.Object is equal to the current Realms.RealmConfiguration; otherwise, false.

References RealmConfiguration.DatabasePath, RealmConfiguration.EncryptionKey, RealmConfiguration.GetHashCode(), RealmConfiguration.MigrationCallback, RealmConfiguration.ReadOnly, RealmConfiguration.SchemaVersion, and RealmConfiguration.ShouldDeleteIfMigrationNeeded.

§ GetHashCode()

override int GetHashCode ( )

Serves as a hash function for a RealmConfiguration based on its path.

Returns
A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.

Referenced by RealmConfiguration.Equals().

§ MigrationCallbackDelegate()

delegate void MigrationCallbackDelegate ( Migration  migration,
ulong  oldSchemaVersion 
)

In order to handle manual migrations, you need to supply one of these to your RealmConfiguration. It will be called with a Migration instance containing the pre- and the post-migration realm. You should make sure that the NewRealm property on it contains a database that is up to date when returning. The oldSchemaVersion parameter will tell you which version the user is migrating from. They should always be migrating to the current version.

Parameters
migrationThe Migration instance, containing information about the old and the new realm.
oldSchemaVersionAn unsigned long value indicating the schema version of the old realm.

§ PathToRealm()

static string PathToRealm ( string  optionalPath = null)
static

Utility to build a path in which a realm will be created so can consistently use filenames and relative paths.

Parameters
optionalPathPath to the realm, must be a valid full path for the current platform, relative subdirectory, or just filename.
Returns
A full path including name of Realm file.

References RealmConfiguration.DefaultRealmName.

Referenced by RealmConfiguration.RealmConfiguration().

Member Data Documentation

§ DefaultRealmName

string DefaultRealmName => "default.realm"
static

Gets the filename to be combined with the platform-specific document directory.

A string representing a filename only, no path.

Referenced by RealmConfiguration.PathToRealm().

§ ReadOnly

bool ReadOnly

Flag to indicate Realm is opened readonly so can open from locked locations such as bundled with an application.

Referenced by RealmConfiguration.Equals().

§ ShouldDeleteIfMigrationNeeded

readonly bool ShouldDeleteIfMigrationNeeded

Flag indicating that the database will be deleted if the schema mismatches the one in the code. Use this when debugging and developing your app but never release it with this flag set to true.

Referenced by RealmConfiguration.Equals().

Property Documentation

§ DatabasePath

string DatabasePath
get

Gets the full path of the realms opened with this configuration, may be overriden by passing in a separate name.

Referenced by RealmConfiguration.ConfigWithPath(), RealmConfiguration.Equals(), and RealmConfiguration.RealmConfiguration().

§ DefaultConfiguration

RealmConfiguration DefaultConfiguration
staticgetset

Gets or sets the configuration that is used when creating a new Realm without specifying a configuration.

Referenced by Realm.DeleteRealm(), and Realm.GetInstance().

§ EncryptionKey

byte [] EncryptionKey
getset

Gets or sets the key, used to encrypt the entire Realm. Once set, must be specified each time file is used.

Full 64byte (512bit) key for AES-256 encryption.

Referenced by RealmConfiguration.Equals().

§ MigrationCallback

MigrationCallbackDelegate MigrationCallback
getset

Gets or sets the migration callback.

Referenced by RealmConfiguration.Equals().

§ ObjectClasses

Type [] ObjectClasses
getset

Gets or sets the list of classes persisted in a Realm opened with this configuration.

Specify classes by type. Searched linearly so order in decreasing frequency of creating objects.

For example: config.ObjectClasses = new Type[] { typeof(CommonClass), typeof(RareClass) };.

Typically left null so by default all RealmObjects will be able to be stored in all realms.

Referenced by Realm.GetInstance().

§ SchemaVersion

ulong SchemaVersion
getset

Gets or sets a number, indicating the version of the schema. Can be used to arbitrarily distinguish between schemas even if they have the same objects and properties.

0-based value initially set to zero so all user-set values will be greater.

Referenced by RealmConfiguration.Equals().