Class ObjectSchema.Builder
A mutable builder that allows you to construct an ObjectSchema instance.
Inherited Members
Namespace: Realms.Schema
Assembly: Realm.dll
Syntax
public class ObjectSchema.Builder : SchemaBuilderBase<Property>, IEnumerable<Property>, IEnumerable
Constructors
| Edit this page View SourceBuilder(string, ObjectType)
Initializes a new instance of the ObjectSchema.Builder class with the provided name.
Declaration
public Builder(string name, ObjectSchema.ObjectType schemaType = ObjectType.RealmObject)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the ObjectSchema this builder describes. |
ObjectSchema.ObjectType | schemaType | The ObjectSchema.ObjectType of the object this builder describes. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ArgumentException | Thrown if |
Builder(Type)
Initializes a new instance of the ObjectSchema.Builder class populated with properties from the
provided type
.
Declaration
public Builder(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The Type that will be used to populate the builder. It must be a RealmObject, an EmbeddedObject, or an AsymmetricObject inheritor. |
Remarks
If you want to use strongly typed API, such as Realm.Add<T> or
Realm.All<T>, you must use this method to build your schema.
Adding new properties is fully supported, but removing or changing properties defined on the class will result
in runtime errors being thrown if those properties are accessed via the object property accessors.
Examples
class Person : RealmObject
{
public string Name { get; set; }
}
var personSchema = new Builder(typeof(Person));
// someTagsCollection is a collection of tags determined at runtime - e.g. obtained
// from a REST API.
foreach (var tag in someTagsCollection)
{
personSchema.Add(Property.Primitive(tag, RealmValueType.Bool));
}
var config = new RealmConfiguration
{
Schema = new[] { personSchema.Build() }
}
using var realm = Realm.GetInstance(config);
// Query for all people with a particular tag
var tag = "Tall";
var matches = realm.All<Person>().Filter($"{tag} = TRUE");
// Get/set the tag of a particular person
var hasTag = person.DynamicApi.Get<bool>(tag);
person.DynamicApi.Set(tag, true);
Properties
| Edit this page View SourceName
Gets or sets the name of the class described by the builder.
Declaration
public string Name { get; set; }
Property Value
Type | Description |
---|---|
string | The name of the class. |
RealmSchemaType
Gets or sets a value indicating the object's ObjectSchema.ObjectType this ObjectSchema.Builder describes.
Declaration
public ObjectSchema.ObjectType RealmSchemaType { get; set; }
Property Value
Type | Description |
---|---|
ObjectSchema.ObjectType | ObjectSchema.ObjectType of the schema of the object. |
Methods
| Edit this page View SourceAdd(Property)
Adds a new Property to this ObjectSchema.Builder.
Declaration
public ObjectSchema.Builder Add(Property item)
Parameters
Type | Name | Description |
---|---|---|
Property | item | The Property to add. |
Returns
Type | Description |
---|---|
ObjectSchema.Builder | The original ObjectSchema.Builder instance to enable chaining multiple Add(Property) calls. |
Build()
Constructs an ObjectSchema from the properties added to this ObjectSchema.Builder.
Declaration
public ObjectSchema Build()
Returns
Type | Description |
---|---|
ObjectSchema | An immutable ObjectSchema instance that contains the properties added to the ObjectSchema.Builder. |