Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/OpenRiaServices.Client/Framework/DomainClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace OpenRiaServices.Client
/// </summary>
public abstract class DomainClient
{
private ReadOnlyCollection<Type> _entityTypes;
private Type[] _entityTypes;

/// <summary>
/// Gets or sets the collection of Entity Types this <see cref="DomainClient"/> will operate on.
Expand All @@ -32,7 +32,7 @@ public IEnumerable<Type> EntityTypes
{
throw new InvalidOperationException(OpenRiaServices.Client.Resource.DomainClient_EntityTypesAlreadyInitialized);
}
this._entityTypes = new ReadOnlyCollection<Type>(value.ToList());
this._entityTypes = value.ToArray();
}
}

Expand Down
16 changes: 2 additions & 14 deletions src/OpenRiaServices.Client/Framework/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,20 +1610,8 @@ protected internal bool CanInvokeAction(string name)
/// </remarks>
/// <returns>Collection of custom method invocations pending for this entity</returns>
[Display(AutoGenerateField = false)]
public IEnumerable<EntityAction> EntityActions
{
get
{
if (this._customMethodInvocations != null)
{
return new ReadOnlyCollection<EntityAction>(this._customMethodInvocations);
}
else
{
return Enumerable.Empty<EntityAction>();
}
}
}
public IReadOnlyCollection<EntityAction> EntityActions
=> this._customMethodInvocations != null ? this._customMethodInvocations : Array.Empty<EntityAction>();

/// <summary>
/// Return the entity identity, suitable for hashing. If the entity
Expand Down
16 changes: 8 additions & 8 deletions src/OpenRiaServices.Client/Framework/EntityChangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class EntityChangeSet : IEnumerable<Entity>
private ReadOnlyCollection<Entity> _addedEntities;
private ReadOnlyCollection<Entity> _removedEntities;
private ReadOnlyCollection<Entity> _modifiedEntities;
private IEnumerable<ChangeSetEntry> _changeSetEntries;
private List<ChangeSetEntry> _changeSetEntries;

internal EntityChangeSet(
ReadOnlyCollection<Entity> addedEntities,
Expand Down Expand Up @@ -42,15 +42,15 @@ internal EntityChangeSet(
/// <summary>
/// Gets the collection of added Entities
/// </summary>
public ReadOnlyCollection<Entity> AddedEntities
public IReadOnlyList<Entity> AddedEntities
{
get
{
return this._addedEntities;
}
internal set
{
this._addedEntities = value;
this._addedEntities = value is ReadOnlyCollection<Entity> list ? list : new ReadOnlyCollection<Entity>(value.ToArray());
}
}

Expand All @@ -70,30 +70,30 @@ public bool IsEmpty
/// <summary>
/// Gets the collection of modified entities
/// </summary>
public ReadOnlyCollection<Entity> ModifiedEntities
public IReadOnlyList<Entity> ModifiedEntities
{
get
{
return this._modifiedEntities;
}
internal set
{
this._modifiedEntities = value;
this._modifiedEntities = value is ReadOnlyCollection<Entity> list ? list : new ReadOnlyCollection<Entity>(value.ToArray());
}
}

/// <summary>
/// Gets the collection of removed entities
/// </summary>
public ReadOnlyCollection<Entity> RemovedEntities
public IReadOnlyList<Entity> RemovedEntities
{
get
{
return this._removedEntities;
}
internal set
{
this._removedEntities = value;
this._removedEntities = value is ReadOnlyCollection<Entity> list ? list : new ReadOnlyCollection<Entity>(value.ToArray());
}
}

Expand All @@ -115,7 +115,7 @@ public override string ToString()
/// Gets the collection of <see cref="ChangeSetEntry"/> items for this changeset.
/// </summary>
/// <returns>A collection of <see cref="ChangeSetEntry"/> items.</returns>
public IEnumerable<ChangeSetEntry> GetChangeSetEntries()
public IReadOnlyCollection<ChangeSetEntry> GetChangeSetEntries()
{
if (this._changeSetEntries == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenRiaServices.Client/Framework/EntityConflict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Entity StoreEntity
/// <summary>
/// Gets a collection of the property names in conflict.
/// </summary>
public IEnumerable<string> PropertyNames
public IReadOnlyCollection<string> PropertyNames
{
get
{
Expand Down
4 changes: 2 additions & 2 deletions src/OpenRiaServices.Client/Framework/ILoadResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ interface ILoadResult
/// entities referenced by the top level entities. The collection returned implements
/// <see cref="System.Collections.Specialized.INotifyCollectionChanged"/>.
/// </summary>
IReadOnlyCollection<Entity> AllEntities { get; }
IReadOnlyList<Entity> AllEntities { get; }

/// <summary>
/// /// Gets all the top level entities loaded by the operation. The collection returned implements
/// <see cref="System.Collections.Specialized.INotifyCollectionChanged"/>.
/// </summary>
IReadOnlyCollection<Entity> Entities { get; }
IReadOnlyList<Entity> Entities { get; }

/// <summary>
/// Gets the total server entity count for the query used by this operation. Automatic
Expand Down
19 changes: 10 additions & 9 deletions src/OpenRiaServices.Client/Framework/Internal/MetaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ public sealed class MetaType
/// </summary>
[ThreadStatic]
private static Dictionary<Type, MetaType> s_metaTypes;
private readonly MetaMember[] _keyMembers;
private readonly bool _requiresValidation;
private readonly bool _requiresObjectValidation;
private readonly Type[] _childTypes;
private readonly Dictionary<string, MetaMember> _metaMembers = new Dictionary<string, MetaMember>();
private readonly ReadOnlyCollection<MetaMember> _dataMembers;
private readonly ReadOnlyCollection<ValidationAttribute> _validationAttributes;
private readonly MetaMember[] _dataMembers;
private readonly ValidationAttribute[] _validationAttributes;
private readonly Dictionary<string, EntityActionAttribute> _customUpdateMethods;

/// <summary>
Expand Down Expand Up @@ -121,13 +122,13 @@ select attribute

this.Type = type;

_validationAttributes = new ReadOnlyCollection<ValidationAttribute>(this.Type.GetCustomAttributes(typeof(ValidationAttribute), true).OfType<ValidationAttribute>().ToArray());
_validationAttributes = this.Type.GetCustomAttributes(typeof(ValidationAttribute), true).OfType<ValidationAttribute>().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<MetaMember>(_metaMembers.Values.Where(m => m.IsKeyMember).OrderBy(m => m.Name).ToArray());
_dataMembers = new ReadOnlyCollection<MetaMember>(_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)
{
Expand Down Expand Up @@ -235,12 +236,12 @@ private static Dictionary<Type, MetaType> MetaTypes
/// Gets the collection of key members for this entity Type.
/// The entries are sorted by Name for identity purposes.
/// </summary>
public ReadOnlyCollection<MetaMember> KeyMembers { get; }
public IReadOnlyList<MetaMember> KeyMembers => _keyMembers;

/// <summary>
/// Gets the collection of data members for this Type.
/// </summary>
public IEnumerable<MetaMember> DataMembers => _dataMembers;
public IReadOnlyList<MetaMember> DataMembers => _dataMembers;

/// <summary>
/// Gets the collection of association members for this entity Type.
Expand All @@ -256,7 +257,7 @@ public IEnumerable<MetaMember> AssociationMembers
/// <summary>
/// Gets the collection of child types this entity Type composes.
/// </summary>
public IEnumerable<Type> ChildTypes => this._childTypes;
public IReadOnlyCollection<Type> ChildTypes => this._childTypes;

/// <summary>
/// Gets a value indicating whether the Type requires any Type or member level
Expand All @@ -279,7 +280,7 @@ public IEnumerable<MetaMember> AssociationMembers
/// <summary>
/// Gets the Type level validation attributes for the underlying Type.
/// </summary>
public IEnumerable<ValidationAttribute> ValidationAttributes => _validationAttributes;
public IReadOnlyCollection<ValidationAttribute> ValidationAttributes => _validationAttributes;

/// <summary>
/// This recursive function visits every property in the type tree. For each property,
Expand Down
6 changes: 3 additions & 3 deletions src/OpenRiaServices.Client/Framework/LoadOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <see cref="System.Collections.Specialized.INotifyCollectionChanged"/>.
/// </summary>
public IReadOnlyCollection<Entity> Entities
public IReadOnlyList<Entity> Entities
{
get
{
Expand All @@ -78,7 +78,7 @@ public IReadOnlyCollection<Entity> Entities
/// entities referenced by the top level entities. The collection returned implements
/// <see cref="System.Collections.Specialized.INotifyCollectionChanged"/>.
/// </summary>
public IReadOnlyCollection<Entity> AllEntities
public IReadOnlyList<Entity> AllEntities
{
get
{
Expand Down Expand Up @@ -232,7 +232,7 @@ public LoadOperation(EntityQuery<TEntity> query,
/// entities referenced by the top level entities. The collection returned implements
/// <see cref="System.Collections.Specialized.INotifyCollectionChanged"/>.
/// </summary>
public new IReadOnlyCollection<TEntity> Entities
public new IReadOnlyList<TEntity> Entities
{
get
{
Expand Down
11 changes: 5 additions & 6 deletions src/OpenRiaServices.Client/Framework/LoadResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace OpenRiaServices.Client
/// <typeparam name="TEntity">The type of the entity loaded.</typeparam>
public class LoadResult<TEntity> : IEnumerable<TEntity>, ICollection, ILoadResult where TEntity : Entity
{
private readonly ReadOnlyCollection<TEntity> _loadedEntites;
private readonly Data.ReadOnlyObservableLoaderCollection<TEntity> _loadedEntites;

/// <summary>
/// Initializes a new instance of the <see cref="LoadResult{TEntity}" /> class.
Expand All @@ -38,7 +38,7 @@ public LoadResult(LoadOperation<TEntity> loadOperation)
/// <param name="entities">Top level entities loaded.</param>
/// <param name="allEntities">All entities loaded.</param>
/// <param name="totalEntityCount">The total entity count.</param>
public LoadResult(EntityQuery<TEntity> query, LoadBehavior loadBehavior, IEnumerable<TEntity> entities, IReadOnlyCollection<Entity> allEntities, int totalEntityCount)
public LoadResult(EntityQuery<TEntity> query, LoadBehavior loadBehavior, IEnumerable<TEntity> entities, IReadOnlyList<Entity> allEntities, int totalEntityCount)
{
_loadedEntites = (entities as Data.ReadOnlyObservableLoaderCollection<TEntity>) ?? new Data.ReadOnlyObservableLoaderCollection<TEntity>(entities.ToList());

Expand All @@ -51,13 +51,13 @@ public LoadResult(EntityQuery<TEntity> query, LoadBehavior loadBehavior, IEnumer
/// <summary>
/// Gets all the top level entities loaded by the operation.
/// </summary>
public IReadOnlyCollection<TEntity> Entities { get { return _loadedEntites; } }
public IReadOnlyList<TEntity> Entities { get { return _loadedEntites; } }

/// <summary>
/// Gets all the entities loaded by the operation, including any
/// entities referenced by the top level entities.
/// </summary>
public IReadOnlyCollection<Entity> AllEntities { get; private set; }
public IReadOnlyList<Entity> AllEntities { get; private set; }

/// <summary>
/// The <see cref="EntityQuery"/> for this load operation.
Expand Down Expand Up @@ -105,8 +105,7 @@ public LoadResult(EntityQuery<TEntity> query, LoadBehavior loadBehavior, IEnumer
protected object SyncRoot { get { return ((ICollection)_loadedEntites).SyncRoot; } }
object ICollection.SyncRoot { get { return this.SyncRoot; } }


IReadOnlyCollection<Entity> ILoadResult.Entities => this.Entities;
IReadOnlyList<Entity> ILoadResult.Entities => this.Entities;

/// <summary>
/// Returns an enumerator that iterates through the collection.
Expand Down
8 changes: 4 additions & 4 deletions src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public QueryCompletedResult(IEnumerable<Entity> entities, IEnumerable<Entity> in
/// <summary>
/// Gets the entities returned from the query
/// </summary>
public IEnumerable<Entity> Entities
public IReadOnlyCollection<Entity> Entities
{
get
{
Expand All @@ -58,7 +58,7 @@ public IEnumerable<Entity> Entities
/// <summary>
/// Gets the included entities returned from the query
/// </summary>
public IEnumerable<Entity> IncludedEntities
public IReadOnlyCollection<Entity> IncludedEntities
{
get
{
Expand All @@ -81,12 +81,12 @@ public int TotalCount
/// <summary>
/// Gets the validation errors.
/// </summary>
public IEnumerable<ValidationResult> ValidationErrors
public IReadOnlyCollection<ValidationResult> ValidationErrors
{
get
{
return this._validationErrors;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down