use packages
1a01174b
Alexander Nosenko
committed
7 changed files
EntityExtensionsContext.Clone.cs
/src/Refactorius.Data.Xrm/Context/EntityExtensionsContext.Clone.cs
/src/Refactorius.Data.Xrm/Context/EntityExtensionsContext.Clone.cs
EntityShadowExtensions.cs
/src/Refactorius.Data.Xrm/Shadow/EntityShadowExtensions.cs-1+44
/src/Refactorius.Data.Xrm/Shadow/EntityShadowExtensions.cs
Add comment 29 where TEntity : Entity, new()
Add comment 30 => entities.Select(x => x.WithShadow());
Add comment 31
Add comment 32 Plus   /// <summary>
Add comment 33 Plus   /// Adds a shadow copy to the partially loaded entity.
Add comment 34 Plus   /// </summary>
Add comment 35 Plus   /// <typeparam name="TEntity">The entity type.</typeparam>
Add comment 36 Plus   /// <param name="entity">The <see cref="Entity"/> instance to add the shadow to.</param>
Add comment 37 Plus   /// <returns>The current <paramref name="entity"/>.</returns>
Add comment 38 Plus   public static TEntity WithPartialShadow<TEntity>(this TEntity entity)
Add comment 39 Plus   where TEntity : Entity, new()
Add comment 40 Plus   {
Add comment 41 Plus   ShadowMixin.AddPartial(entity);
Add comment 42 Plus   return entity;
Add comment 43 Plus   }
Add comment 44 Plus  
Add comment 45 Plus   /// <summary>
Add comment 46 Plus   /// Adds a shadow copy to partially loaded entities sequence.
Add comment 47 Plus   /// </summary>
Add comment 48 Plus   /// <typeparam name="TEntity">The entity type.</typeparam>
Add comment 49 Plus   /// <param name="entities">The <see cref="Entity"/> instances to add the shadow to.</param>
Add comment 50 Plus   /// <returns>The pass-through <paramref name="entities"/> sequence.</returns>
Add comment 51 Plus   public static IEnumerable<TEntity> WithPartialShadow<TEntity>(this IEnumerable<TEntity> entities)
Add comment 52 Plus   where TEntity : Entity, new()
Add comment 53 Plus   => entities.Select(x => x.WithPartialShadow());
Add comment 54 Plus  
Add comment 32 55 /// <inheritdoc cref="ShadowMixin.GetChanges{TEntity}(TEntity, out TEntity)" />
Add comment 33 Minus   public static TEntity GetChanges<TEntity>(this TEntity entity, out TEntity shadow)
Add comment 56 Plus   public static TEntity? GetChanges<TEntity>(this TEntity entity, out TEntity? shadow)
Add comment 34 57 where TEntity : Entity, new()
Add comment 35 58 {
Add comment 36 59 return ShadowMixin.GetChanges(entity, out shadow);
Add comment 37 60 }
Add comment 61 Plus  
Add comment 62 Plus   /// <summary>
Add comment 63 Plus   /// Tests whether the entity is a partially loaded shadow.
Add comment 64 Plus   /// </summary>
Add comment 65 Plus   /// <param name="entity">The entity (usually but not necessary a shadow).</param>
Add comment 66 Plus   /// <returns><see langword="true"/> if the <paramref name="entity"/> was only partially loaded, otherwise <see langword="false"/>.</returns>
Add comment 67 Plus   public static bool IsPartial(this Entity entity)
Add comment 68 Plus   => entity.GetAttributeValue<bool?>(ShadowMixin.PartialLoadFlag) ?? false;
Add comment 69 Plus  
Add comment 70 Plus   /// <summary>
Add comment 71 Plus   /// Marks entity as partially loaded.
Add comment 72 Plus   /// </summary>
Add comment 73 Plus   /// <typeparam name="TEntity">The type of the entity.</typeparam>
Add comment 74 Plus   /// <param name="entity">The entity to mark.</param>
Add comment 75 Plus   /// <returns>The original <paramref name="entity"/> for call chaining.</returns>
Add comment 76 Plus   public static TEntity MarkAsPartial<TEntity>(this TEntity entity) where TEntity:Entity
Add comment 77 Plus   {
Add comment 78 Plus   entity[ShadowMixin.PartialLoadFlag] = true;
Add comment 79 Plus   return entity;
Add comment 80 Plus   }
Add comment 38 81 }
ShadowMixin.cs
/src/Refactorius.Data.Xrm/Shadow/ShadowMixin.cs+17
/src/Refactorius.Data.Xrm/Shadow/ShadowMixin.cs
Add comment 7 /// </summary>
Add comment 8 public class ShadowMixin : MixinBase<Entity, Entity>
Add comment 9 {
Add comment 10 Plus   /// <summary>
Add comment 11 Plus   /// The pseudo-attribute marking partially loaded entity.
Add comment 12 Plus   /// </summary>
Add comment 13 Plus   public const string PartialLoadFlag = "$partialLoad";
Add comment 14 Plus  
Add comment 10 15 private static readonly KeyValuePair<string, object?>[] _emptyBag = Array.Empty<KeyValuePair<string, object?>>();
Add comment 16 Plus   //private static readonly KeyValuePair<string, object?>[] _partialLoadBag = { KeyValuePair.Create(PartialLoadFlag, (object?)true)};
Add comment 11 17
Add comment 18 Plus  
Add comment 12 19 /// <summary>
Add comment 13 20 /// Initializes a new instance of the <see cref="ShadowMixin"/> mixin.
Add comment 14 21 /// </summary>
Add comment 30 37 Add(key, CloneToShadow(key));
Add comment 31 38 }
Add comment 32 39
Add comment 40 Plus   /// <summary>
Add comment 41 Plus   /// Makes a shadow copy of a partially loaded entity.
Add comment 42 Plus   /// </summary>
Add comment 43 Plus   /// <param name="key">The <see cref="Entity"/> instance to add the shadow to.</param>
Add comment 44 Plus   public static void AddPartial<TEntity>(TEntity key)
Add comment 45 Plus   where TEntity : Entity, new()
Add comment 46 Plus   {
Add comment 47 Plus   Add(key, CloneToShadow(key).MarkAsPartial());
Add comment 48 Plus   }
Add comment 49 Plus  
Add comment 33 50 // NB: only writables, including ID
Add comment 34 51 private static TEntity CloneToShadow<TEntity>(TEntity entity)
Add comment 35 52 where TEntity : Entity, new()
Refactorius.Data.Xrm.csproj
/src/Refactorius.Data.Xrm/Refactorius.Data.Xrm.csproj
/src/Refactorius.Data.Xrm/Refactorius.Data.Xrm.csproj
Refactorius.Data.Xrm.Tests.csproj
/tests/Refactorius.Data.Xrm.Tests/Refactorius.Data.Xrm.Tests.csproj
/tests/Refactorius.Data.Xrm.Tests/Refactorius.Data.Xrm.Tests.csproj
NuGet.Config
/NuGet.Config
/NuGet.Config
Refactorius.Data.Xrm.sln
/Refactorius.Data.Xrm.sln
/Refactorius.Data.Xrm.sln