diff --git a/CHANGELOG.md b/CHANGELOG.md index 1065bfd2cd..1213060149 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,11 @@ * Removed `DiscardLocalResetHandler` - use `DiscardUnsyncedChangedHandler` instead. (PR [#3237](https://github.com/realm/realm-dotnet/pull/3237)) * Removed `Session.SimulateClientReset` extensions. These didn't work with automatic reset handlers and were more confusing than helpful. (PR [#3237](https://github.com/realm/realm-dotnet/pull/3237)) * Removed `AppConfiguration.CustomLogger` and `AppConfiguration.LogLevel` - use `Logger.Default` and `Logger.LogLevel` instead. (PR [#3238](https://github.com/realm/realm-dotnet/pull/3238)) +* Removed `RealmConfigurationBase.ObjectClasses` - use `RealmConfigurationBase.Schema` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) +* Removed `ObjectSchema.IsEmbedded` - use `ObjectSchema.BaseType` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) +* Removed `ObjectSchema.Builder.IsEmbedded` - use `ObjectSchema.Builder.RealmSchemaType` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) +* Removed `ObjectSchema.Builder(string name, bool isEmbedded = false)` - use `Builder(string name, ObjectSchemaType schemaType)` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) +* Removed `RealmSchema.Find` - use `RealmSchema.TryFindObjectSchema` instead. (PR [#3239](https://github.com/realm/realm-dotnet/pull/3239)) ### Enhancements diff --git a/Realm/Realm/Attributes/ExplicitAttribute.cs b/Realm/Realm/Attributes/ExplicitAttribute.cs index 0c2183277f..764346abb3 100644 --- a/Realm/Realm/Attributes/ExplicitAttribute.cs +++ b/Realm/Realm/Attributes/ExplicitAttribute.cs @@ -25,8 +25,8 @@ namespace Realms /// /// /// If applied at the assembly level, then all classes in that assembly will be considered explicit and will not be added to - /// the default schema. To include explicit classes in a Realm's schema, you should include them in the - /// array: + /// the default schema. To include explicit classes in a Realm's schema, you should include them in + /// : /// /// var config = new RealmConfiguration /// { @@ -40,4 +40,4 @@ namespace Realms public class ExplicitAttribute : Attribute { } -} \ No newline at end of file +} diff --git a/Realm/Realm/Configurations/RealmConfigurationBase.cs b/Realm/Realm/Configurations/RealmConfigurationBase.cs index 07c2d555ad..b2e655ed35 100644 --- a/Realm/Realm/Configurations/RealmConfigurationBase.cs +++ b/Realm/Realm/Configurations/RealmConfigurationBase.cs @@ -68,29 +68,6 @@ public abstract class RealmConfigurationBase internal bool EnableCache = true; - /// - /// Gets or sets the list of classes persisted in a Realm opened with this configuration. - /// - /// - /// Typically left null so by default all s and s will be able to be stored in all Realms. - /// - /// - /// - /// config.ObjectClasses = new Type[] - /// { - /// typeof(CommonClass), - /// typeof(RareClass) - /// }; - /// - /// - /// The classes that can be persisted in the Realm. - [Obsolete("Use Schema = new[] { typeof(...) } instead.")] - public Type[] ObjectClasses - { - get => Schema?.Select(s => s.Type).Where(t => t != null).ToArray(); - set => Schema = value; - } - /// /// Gets or sets the schema of the Realm opened with this configuration. /// diff --git a/Realm/Realm/Schema/ObjectSchema.cs b/Realm/Realm/Schema/ObjectSchema.cs index e03bd9c8ad..a151feeb60 100644 --- a/Realm/Realm/Schema/ObjectSchema.cs +++ b/Realm/Realm/Schema/ObjectSchema.cs @@ -56,7 +56,7 @@ public enum ObjectType : byte AsymmetricObject = 2, } - private static readonly ConcurrentDictionary _cache = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary _cache = new(); private readonly ReadOnlyDictionary _properties; @@ -76,13 +76,6 @@ public enum ObjectType : byte internal Type Type { get; private set; } - /// - /// Gets a value indicating whether this describes an embedded object. - /// - /// true if the schema pertains to an instance; false otherwise. - [Obsolete("Check against BaseType instead.")] - public bool IsEmbedded => BaseType == ObjectType.EmbeddedObject; - /// /// Gets a indicating whether this describes /// a top level object, an embedded object or an asymmetric object. @@ -170,25 +163,6 @@ public class Builder : SchemaBuilderBase /// The name of the class. public string Name { get; set; } - /// - /// Gets or sets a value indicating whether this describes an embedded object. - /// - /// true if the schema pertains to an instance; false otherwise. - [Obsolete("Check against RealmSchemaType instead.")] - public bool IsEmbedded - { - get - { - return RealmSchemaType == ObjectType.EmbeddedObject; - } - - set - { - // being an obsolete method, it's assumed that it's old code that doesn't use AsymmetricObjects - RealmSchemaType = value ? ObjectType.EmbeddedObject : ObjectType.RealmObject; - } - } - /// /// Gets or sets a value indicating the object's this describes. /// @@ -202,7 +176,7 @@ public bool IsEmbedded /// The of the object this builder describes. /// Thrown if is null. /// Thrown if is the empty string. - public Builder(string name, ObjectType schemaType) + public Builder(string name, ObjectType schemaType = ObjectType.RealmObject) { Argument.NotNullOrEmpty(name, nameof(name)); @@ -210,21 +184,6 @@ public Builder(string name, ObjectType schemaType) RealmSchemaType = schemaType; } - /// - /// Initializes a new instance of the class with the provided name. - /// - /// The name of the this builder describes. - /// A flag indicating whether the object is embedded or not. - /// - /// Thrown if is null. - /// Thrown if is the empty string. - [Obsolete("Use Builder(string name, ObjectSchemaType schemaType) instead.")] - public Builder(string name, bool isEmbedded = false) - : this(name, - isEmbedded ? ObjectType.EmbeddedObject : ObjectType.RealmObject) - { - } - /// /// Initializes a new instance of the class populated with properties from the /// provided . @@ -312,7 +271,7 @@ public Builder(Type type) /// Constructs an from the properties added to this . /// /// An immutable instance that contains the properties added to the . - public ObjectSchema Build() => new ObjectSchema(Name, RealmSchemaType, _values) { Type = Type }; + public ObjectSchema Build() => new(Name, RealmSchemaType, _values) { Type = Type }; /// /// Adds a new to this . diff --git a/Realm/Realm/Schema/RealmSchema.cs b/Realm/Realm/Schema/RealmSchema.cs index b8c255ca29..20b5045311 100644 --- a/Realm/Realm/Schema/RealmSchema.cs +++ b/Realm/Realm/Schema/RealmSchema.cs @@ -114,21 +114,6 @@ private RealmSchema(IDictionary objectSchemas) _objects = new ReadOnlyDictionary(objectSchemas); } - /// - /// Finds the definition of a class in this schema. - /// - /// A valid class name which may be in this schema. - /// Thrown if a name is not supplied. - /// An or null to indicate not found. - [Obsolete("This method is obsolete. Use TryFindObjectSchema instead.")] - public ObjectSchema Find(string name) - { - Argument.NotNullOrEmpty(name, nameof(name)); - - _objects.TryGetValue(name, out var obj); - return obj; - } - /// /// Attempts to find the definition of a class in this schema. /// diff --git a/Tests/Realm.Tests/Database/InMemoryTests.cs b/Tests/Realm.Tests/Database/InMemoryTests.cs index 6f9e1bf7ab..c44ba525fb 100644 --- a/Tests/Realm.Tests/Database/InMemoryTests.cs +++ b/Tests/Realm.Tests/Database/InMemoryTests.cs @@ -148,16 +148,6 @@ public void InMemoryRealm_WhenGarbageCollected_DeletesData() }); } - [Test] - [Obsolete("Tests obsolete functionality")] - public void InMemoryRealm_WhenEncrypted_Throws() - { - Assert.Throws(() => _ = new InMemoryConfiguration(_config.Identifier) - { - EncryptionKey = TestHelpers.GetEncryptionKey(23) - }); - } - [Test] public void InMemoryRealmWithFrozenObjects_WhenDeleted_DoesNotThrow() { diff --git a/Tests/Realm.Tests/Database/InstanceTests.cs b/Tests/Realm.Tests/Database/InstanceTests.cs index 46335a2e3d..e2d088e7f0 100644 --- a/Tests/Realm.Tests/Database/InstanceTests.cs +++ b/Tests/Realm.Tests/Database/InstanceTests.cs @@ -1226,90 +1226,6 @@ public void GetInstance_WithTypedSchemaWithMissingProperties_ThrowsException() }); } - [Test] - [Obsolete("Tests obsoleted functionality")] - public void GetInstance_WithObjectClasses_SetsCorrectSchema() - { - var config = new RealmConfiguration(Guid.NewGuid().ToString()) - { - ObjectClasses = new[] { typeof(AllTypesObject) } - }; - - Assert.That(config.ObjectClasses, Is.Not.Null); - Assert.That(config.Schema, Is.Not.Null); - - Assert.That(config.Schema.Count, Is.EqualTo(1)); - Assert.That(config.Schema.TryFindObjectSchema(nameof(AllTypesObject), out var atoSchema), Is.True); - Assert.That(atoSchema.Type, Is.EqualTo(typeof(AllTypesObject))); - - using var realm = GetRealm(config); - - var allAtos = realm.All(); - Assert.That(allAtos.Count(), Is.EqualTo(0)); - - var ex = Assert.Throws(() => realm.All()); - Assert.That(ex.Message, Does.Contain($"The class {nameof(Person)} is not in the limited set of classes for this realm")); - } - - [Test] - [Obsolete("Tests obsoleted functionality")] - public void GetInstance_WithSchema_ReturnsCorrectObjectClasses() - { - var config = new RealmConfiguration(Guid.NewGuid().ToString()) - { - Schema = new[] { typeof(AllTypesObject) } - }; - - Assert.That(config.ObjectClasses, Is.Not.Null); - Assert.That(config.Schema, Is.Not.Null); - - Assert.That(config.ObjectClasses.Count, Is.EqualTo(1)); - Assert.That(config.ObjectClasses.Single(), Is.EqualTo(typeof(AllTypesObject))); - - using var realm = GetRealm(config); - - var allAtos = realm.All(); - Assert.That(allAtos.Count(), Is.EqualTo(0)); - - var ex = Assert.Throws(() => realm.All()); - Assert.That(ex.Message, Does.Contain($"The class {nameof(Person)} is not in the limited set of classes for this realm")); - } - - [Test] - [Obsolete("Tests obsoleted functionality")] - public void GetInstance_WithSchema_MixingManualAndTyped_ReturnsCorrectObjectClasses() - { - var builder = new RealmSchema.Builder(new[] { typeof(AllTypesObject) }); - builder.Add(new ObjectSchema.Builder("Foo") - { - Property.FromType("Bar") - }); - - builder.Add(typeof(Person)); - - var config = new RealmConfiguration(Guid.NewGuid().ToString()) - { - Schema = builder.Build() - }; - - Assert.That(config.ObjectClasses, Is.Not.Null); - Assert.That(config.Schema, Is.Not.Null); - - Assert.That(config.ObjectClasses.Count, Is.EqualTo(2)); - Assert.That(config.ObjectClasses, Is.EquivalentTo(new[] { typeof(AllTypesObject), typeof(Person) })); - - using var realm = GetRealm(config); - - var allAtos = realm.All(); - Assert.That(allAtos.Count(), Is.EqualTo(0)); - - var ex = Assert.Throws(() => realm.All()); - Assert.That(ex.Message, Does.Contain($"The class {nameof(IntPropertyObject)} is not in the limited set of classes for this realm")); - - var allFoos = realm.DynamicApi.All("Foo"); - Assert.That(allFoos.Count(), Is.EqualTo(0)); - } - [Test] public void RealmWithFrozenObjects_WhenDeleted_DoesNotThrow() { diff --git a/Tests/Realm.Tests/Database/ObjectSchemaTests.cs b/Tests/Realm.Tests/Database/ObjectSchemaTests.cs index 5cc1d0d8d7..fff7711ce3 100644 --- a/Tests/Realm.Tests/Database/ObjectSchemaTests.cs +++ b/Tests/Realm.Tests/Database/ObjectSchemaTests.cs @@ -65,13 +65,6 @@ public void Property_WhenRequired_ShouldBeNonNullable() Assert.That(prop.Type.HasFlag(PropertyType.Nullable), Is.False); } - [Test] - [Obsolete("Remove when we remove RealmSchema.Find")] - public void Class_WhenExplicit_ShouldNotBeInDefaultSchema_Legacy() - { - Assert.That(RealmSchema.Default.Find(nameof(ExplicitClass)), Is.Null); - } - [Test] public void Class_WhenExplicit_ShouldNotBeInDefaultSchema() { @@ -562,26 +555,6 @@ public void ObjectSchemaBuilder_CanBuildEmptySchema() Assert.That(builder.RealmSchemaType, Is.EqualTo(ObjectSchema.ObjectType.EmbeddedObject)); } - [Test, Obsolete("Testing depreccated ObjectSchema.Builder API")] - public void ObjectSchemaBuilder_ObsoleteAPIKeepsWorking() - { - var myClassBuilder = new ObjectSchema.Builder("myClass"); - myClassBuilder.Add(Property.FromType("Foo")); - var myClassSchema = myClassBuilder.Build(); - - Assert.That(myClassSchema.Count, Is.EqualTo(1)); - Assert.That(myClassSchema.Name, Is.EqualTo("myClass")); - Assert.That(myClassBuilder["Foo"].Type, Is.EqualTo(PropertyType.Int)); - Assert.That(myClassBuilder.RealmSchemaType, Is.EqualTo(ObjectSchema.ObjectType.RealmObject)); - - var myOtherClassBuilder = new ObjectSchema.Builder("myOtherClass", isEmbedded: true); - var myOtherClassSchema = myOtherClassBuilder.Build(); - - Assert.That(myOtherClassSchema.Count, Is.EqualTo(0)); - Assert.That(myOtherClassSchema.Name, Is.EqualTo("myOtherClass")); - Assert.That(myOtherClassBuilder.RealmSchemaType, Is.EqualTo(ObjectSchema.ObjectType.EmbeddedObject)); - } - [Test] public void ObjectSchemaBuilder_InvalidArguments() {