Search Results for

    Show / Hide Table of Contents

    Class ObjectSchema.Builder

    A mutable builder that allows you to construct an ObjectSchema instance.

    Inheritance
    object
    SchemaBuilderBase<Property>
    ObjectSchema.Builder
    Implements
    IEnumerable<Property>
    IEnumerable
    Inherited Members
    SchemaBuilderBase<Property>.this[string]
    SchemaBuilderBase<Property>.Count
    SchemaBuilderBase<Property>.Remove(Property)
    SchemaBuilderBase<Property>.Remove(string)
    SchemaBuilderBase<Property>.Contains(Property)
    SchemaBuilderBase<Property>.Contains(string)
    Namespace: Realms.Schema
    Assembly: Realm.dll
    Syntax
    public class ObjectSchema.Builder : SchemaBuilderBase<Property>, IEnumerable<Property>, IEnumerable

    Constructors

    | Edit this page View Source

    Builder(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 name is null.

    ArgumentException

    Thrown if name is the empty string.

    | Edit this page View Source

    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 or an EmbeddedObject 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 Source

    Name

    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.

    | Edit this page View Source

    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 Source

    Add(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.

    | Edit this page View Source

    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.

    Implements

    IEnumerable<T>
    IEnumerable
    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2020-2024 Realm
    Generated by DocFX