diff --git a/src/OpenRiaServices.Client/Framework/DomainClient.cs b/src/OpenRiaServices.Client/Framework/DomainClient.cs index 28c66be69..7b6b8eeff 100644 --- a/src/OpenRiaServices.Client/Framework/DomainClient.cs +++ b/src/OpenRiaServices.Client/Framework/DomainClient.cs @@ -15,7 +15,7 @@ namespace OpenRiaServices.Client /// public abstract class DomainClient { - private ReadOnlyCollection _entityTypes; + private Type[] _entityTypes; /// /// Gets or sets the collection of Entity Types this will operate on. @@ -32,7 +32,7 @@ public IEnumerable EntityTypes { throw new InvalidOperationException(OpenRiaServices.Client.Resource.DomainClient_EntityTypesAlreadyInitialized); } - this._entityTypes = new ReadOnlyCollection(value.ToList()); + this._entityTypes = value.ToArray(); } } diff --git a/src/OpenRiaServices.Client/Framework/Entity.cs b/src/OpenRiaServices.Client/Framework/Entity.cs index 8757f4f3a..5ade6b54a 100644 --- a/src/OpenRiaServices.Client/Framework/Entity.cs +++ b/src/OpenRiaServices.Client/Framework/Entity.cs @@ -1610,20 +1610,8 @@ protected internal bool CanInvokeAction(string name) /// /// Collection of custom method invocations pending for this entity [Display(AutoGenerateField = false)] - public IEnumerable EntityActions - { - get - { - if (this._customMethodInvocations != null) - { - return new ReadOnlyCollection(this._customMethodInvocations); - } - else - { - return Enumerable.Empty(); - } - } - } + public IReadOnlyCollection EntityActions + => this._customMethodInvocations != null ? this._customMethodInvocations : Array.Empty(); /// /// Return the entity identity, suitable for hashing. If the entity diff --git a/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs b/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs index 0b1aef4fc..6a96ae10d 100644 --- a/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs +++ b/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs @@ -14,7 +14,7 @@ public sealed class EntityChangeSet : IEnumerable private ReadOnlyCollection _addedEntities; private ReadOnlyCollection _removedEntities; private ReadOnlyCollection _modifiedEntities; - private IEnumerable _changeSetEntries; + private List _changeSetEntries; internal EntityChangeSet( ReadOnlyCollection addedEntities, @@ -42,7 +42,7 @@ internal EntityChangeSet( /// /// Gets the collection of added Entities /// - public ReadOnlyCollection AddedEntities + public IReadOnlyList AddedEntities { get { @@ -50,7 +50,7 @@ public ReadOnlyCollection AddedEntities } internal set { - this._addedEntities = value; + this._addedEntities = value is ReadOnlyCollection list ? list : new ReadOnlyCollection(value.ToArray()); } } @@ -70,7 +70,7 @@ public bool IsEmpty /// /// Gets the collection of modified entities /// - public ReadOnlyCollection ModifiedEntities + public IReadOnlyList ModifiedEntities { get { @@ -78,14 +78,14 @@ public ReadOnlyCollection ModifiedEntities } internal set { - this._modifiedEntities = value; + this._modifiedEntities = value is ReadOnlyCollection list ? list : new ReadOnlyCollection(value.ToArray()); } } /// /// Gets the collection of removed entities /// - public ReadOnlyCollection RemovedEntities + public IReadOnlyList RemovedEntities { get { @@ -93,7 +93,7 @@ public ReadOnlyCollection RemovedEntities } internal set { - this._removedEntities = value; + this._removedEntities = value is ReadOnlyCollection list ? list : new ReadOnlyCollection(value.ToArray()); } } @@ -115,7 +115,7 @@ public override string ToString() /// Gets the collection of items for this changeset. /// /// A collection of items. - public IEnumerable GetChangeSetEntries() + public IReadOnlyCollection GetChangeSetEntries() { if (this._changeSetEntries == null) { diff --git a/src/OpenRiaServices.Client/Framework/EntityConflict.cs b/src/OpenRiaServices.Client/Framework/EntityConflict.cs index cfc15be04..ff211423d 100644 --- a/src/OpenRiaServices.Client/Framework/EntityConflict.cs +++ b/src/OpenRiaServices.Client/Framework/EntityConflict.cs @@ -103,7 +103,7 @@ public Entity StoreEntity /// /// Gets a collection of the property names in conflict. /// - public IEnumerable PropertyNames + public IReadOnlyCollection PropertyNames { get { diff --git a/src/OpenRiaServices.Client/Framework/ILoadResult.cs b/src/OpenRiaServices.Client/Framework/ILoadResult.cs index 235a7e1ca..67379634d 100644 --- a/src/OpenRiaServices.Client/Framework/ILoadResult.cs +++ b/src/OpenRiaServices.Client/Framework/ILoadResult.cs @@ -13,13 +13,13 @@ interface ILoadResult /// entities referenced by the top level entities. The collection returned implements /// . /// - IReadOnlyCollection AllEntities { get; } + IReadOnlyList AllEntities { get; } /// /// /// Gets all the top level entities loaded by the operation. The collection returned implements /// . /// - IReadOnlyCollection Entities { get; } + IReadOnlyList Entities { get; } /// /// Gets the total server entity count for the query used by this operation. Automatic diff --git a/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs b/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs index 31914d516..e223b6d1a 100644 --- a/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs +++ b/src/OpenRiaServices.Client/Framework/Internal/MetaType.cs @@ -31,12 +31,13 @@ public sealed class MetaType /// [ThreadStatic] private static Dictionary s_metaTypes; + private readonly MetaMember[] _keyMembers; private readonly bool _requiresValidation; private readonly bool _requiresObjectValidation; private readonly Type[] _childTypes; private readonly Dictionary _metaMembers = new Dictionary(); - private readonly ReadOnlyCollection _dataMembers; - private readonly ReadOnlyCollection _validationAttributes; + private readonly MetaMember[] _dataMembers; + private readonly ValidationAttribute[] _validationAttributes; private readonly Dictionary _customUpdateMethods; /// @@ -121,13 +122,13 @@ select attribute this.Type = type; - _validationAttributes = new ReadOnlyCollection(this.Type.GetCustomAttributes(typeof(ValidationAttribute), true).OfType().ToArray()); + _validationAttributes = this.Type.GetCustomAttributes(typeof(ValidationAttribute), true).OfType().ToArray(); _requiresObjectValidation = _validationAttributes.Any() || typeof(IValidatableObject).IsAssignableFrom(type); _requiresValidation = _requiresValidation || _requiresObjectValidation; // for identity purposes, we need to make sure values are always ordered - KeyMembers = new ReadOnlyCollection(_metaMembers.Values.Where(m => m.IsKeyMember).OrderBy(m => m.Name).ToArray()); - _dataMembers = new ReadOnlyCollection(_metaMembers.Values.Where(m => m.IsDataMember).ToArray()); + _keyMembers = _metaMembers.Values.Where(m => m.IsKeyMember).OrderBy(m => m.Name).ToArray(); + _dataMembers = _metaMembers.Values.Where(m => m.IsDataMember).ToArray(); if (!_requiresValidation && HasComplexMembers) { @@ -235,12 +236,12 @@ private static Dictionary MetaTypes /// Gets the collection of key members for this entity Type. /// The entries are sorted by Name for identity purposes. /// - public ReadOnlyCollection KeyMembers { get; } + public IReadOnlyList KeyMembers => _keyMembers; /// /// Gets the collection of data members for this Type. /// - public IEnumerable DataMembers => _dataMembers; + public IReadOnlyList DataMembers => _dataMembers; /// /// Gets the collection of association members for this entity Type. @@ -256,7 +257,7 @@ public IEnumerable AssociationMembers /// /// Gets the collection of child types this entity Type composes. /// - public IEnumerable ChildTypes => this._childTypes; + public IReadOnlyCollection ChildTypes => this._childTypes; /// /// Gets a value indicating whether the Type requires any Type or member level @@ -279,7 +280,7 @@ public IEnumerable AssociationMembers /// /// Gets the Type level validation attributes for the underlying Type. /// - public IEnumerable ValidationAttributes => _validationAttributes; + public IReadOnlyCollection ValidationAttributes => _validationAttributes; /// /// This recursive function visits every property in the type tree. For each property, diff --git a/src/OpenRiaServices.Client/Framework/LoadOperation.cs b/src/OpenRiaServices.Client/Framework/LoadOperation.cs index 1d1e929e2..6f01a0a08 100644 --- a/src/OpenRiaServices.Client/Framework/LoadOperation.cs +++ b/src/OpenRiaServices.Client/Framework/LoadOperation.cs @@ -60,7 +60,7 @@ private protected LoadOperation(EntityQuery query, LoadBehavior loadBehavior, ob /// Gets all the top level entities loaded by the operation. The collection returned implements /// . /// - public IReadOnlyCollection Entities + public IReadOnlyList Entities { get { @@ -78,7 +78,7 @@ public IReadOnlyCollection Entities /// entities referenced by the top level entities. The collection returned implements /// . /// - public IReadOnlyCollection AllEntities + public IReadOnlyList AllEntities { get { @@ -232,7 +232,7 @@ public LoadOperation(EntityQuery query, /// entities referenced by the top level entities. The collection returned implements /// . /// - public new IReadOnlyCollection Entities + public new IReadOnlyList Entities { get { diff --git a/src/OpenRiaServices.Client/Framework/LoadResult.cs b/src/OpenRiaServices.Client/Framework/LoadResult.cs index 761e8650b..fec4c57ac 100644 --- a/src/OpenRiaServices.Client/Framework/LoadResult.cs +++ b/src/OpenRiaServices.Client/Framework/LoadResult.cs @@ -16,7 +16,7 @@ namespace OpenRiaServices.Client /// The type of the entity loaded. public class LoadResult : IEnumerable, ICollection, ILoadResult where TEntity : Entity { - private readonly ReadOnlyCollection _loadedEntites; + private readonly Data.ReadOnlyObservableLoaderCollection _loadedEntites; /// /// Initializes a new instance of the class. @@ -38,7 +38,7 @@ public LoadResult(LoadOperation loadOperation) /// Top level entities loaded. /// All entities loaded. /// The total entity count. - public LoadResult(EntityQuery query, LoadBehavior loadBehavior, IEnumerable entities, IReadOnlyCollection allEntities, int totalEntityCount) + public LoadResult(EntityQuery query, LoadBehavior loadBehavior, IEnumerable entities, IReadOnlyList allEntities, int totalEntityCount) { _loadedEntites = (entities as Data.ReadOnlyObservableLoaderCollection) ?? new Data.ReadOnlyObservableLoaderCollection(entities.ToList()); @@ -51,13 +51,13 @@ public LoadResult(EntityQuery query, LoadBehavior loadBehavior, IEnumer /// /// Gets all the top level entities loaded by the operation. /// - public IReadOnlyCollection Entities { get { return _loadedEntites; } } + public IReadOnlyList Entities { get { return _loadedEntites; } } /// /// Gets all the entities loaded by the operation, including any /// entities referenced by the top level entities. /// - public IReadOnlyCollection AllEntities { get; private set; } + public IReadOnlyList AllEntities { get; private set; } /// /// The for this load operation. @@ -105,8 +105,7 @@ public LoadResult(EntityQuery query, LoadBehavior loadBehavior, IEnumer protected object SyncRoot { get { return ((ICollection)_loadedEntites).SyncRoot; } } object ICollection.SyncRoot { get { return this.SyncRoot; } } - - IReadOnlyCollection ILoadResult.Entities => this.Entities; + IReadOnlyList ILoadResult.Entities => this.Entities; /// /// Returns an enumerator that iterates through the collection. diff --git a/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs b/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs index 7995b1b0f..96e19a0d9 100644 --- a/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs +++ b/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs @@ -47,7 +47,7 @@ public QueryCompletedResult(IEnumerable entities, IEnumerable in /// /// Gets the entities returned from the query /// - public IEnumerable Entities + public IReadOnlyCollection Entities { get { @@ -58,7 +58,7 @@ public IEnumerable Entities /// /// Gets the included entities returned from the query /// - public IEnumerable IncludedEntities + public IReadOnlyCollection IncludedEntities { get { @@ -81,7 +81,7 @@ public int TotalCount /// /// Gets the validation errors. /// - public IEnumerable ValidationErrors + public IReadOnlyCollection ValidationErrors { get { @@ -89,4 +89,4 @@ public IEnumerable ValidationErrors } } } -} \ No newline at end of file +} diff --git a/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/ServerSideAsyncTests.cs b/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/ServerSideAsyncTests.cs index cf3662a19..1bc89b5b4 100644 --- a/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/ServerSideAsyncTests.cs +++ b/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/ServerSideAsyncTests.cs @@ -346,7 +346,7 @@ public async Task Insert_TaskAsync() // Verify Assert.AreEqual(42, rangeItem.Id); - CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.AddedEntities); + CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.AddedEntities.ToList()); } [TestMethod] @@ -382,7 +382,7 @@ public async Task Update_TaskAsync() // Verify Assert.AreEqual("updated", rangeItem.Text); - CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.ModifiedEntities); + CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.ModifiedEntities.ToList()); } [TestMethod] @@ -421,7 +421,7 @@ public async Task EntityAction_TaskAsync() // Verify Assert.AreEqual("custom updated", rangeItem.Text); - CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.ModifiedEntities); + CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.ModifiedEntities.ToList()); } [TestMethod] @@ -457,7 +457,7 @@ public async Task Delete_TaskAsync() var result = await ctx.SubmitChangesAsync(); // Verify - CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.RemovedEntities); + CollectionAssert.AreEqual(new[] { rangeItem }, result.ChangeSet.RemovedEntities.ToList()); } [TestMethod]