Merge pull request #9239 from xyfy/patch-4

Add an `remove` extentions in AutoEntityDistributedEventSelectorListExtensions.cs  adjust the `Add<TEntity>`
pull/9453/head
maliming 4 years ago committed by GitHub
commit bf96281ae7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,7 +26,7 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
)
);
}
/// <summary>
/// Adds a specific entity type and the types derived from that entity type.
/// </summary>
@ -49,14 +49,27 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
)
);
}
/// <summary>
/// Remove a specific entity type and the types derived from that entity type.
/// </summary>
/// <typeparam name="TEntity">Type of the entity</typeparam>
public static void Remove<TEntity>([NotNull] this IAutoEntityDistributedEventSelectorList selectors)
where TEntity : IEntity
{
Check.NotNull(selectors, nameof(selectors));
var selectorName = "Entity:" + typeof(TEntity).FullName;
selectors.RemoveAll(s => s.Name == selectorName);
}
/// <summary>
/// Adds all entity types.
/// </summary>
public static void AddAll([NotNull] this IAutoEntityDistributedEventSelectorList selectors)
{
Check.NotNull(selectors, nameof(selectors));
if (selectors.Any(s => s.Name == AllEntitiesSelectorName))
{
return;
@ -72,11 +85,11 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
public static void Add(
[NotNull] this IAutoEntityDistributedEventSelectorList selectors,
string selectorName,
string selectorName,
Func<Type, bool> predicate)
{
Check.NotNull(selectors, nameof(selectors));
if (selectors.Any(s => s.Name == selectorName))
{
throw new AbpException($"There is already a selector added before with the same name: {selectorName}");
@ -89,7 +102,7 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
)
);
}
public static void Add(
[NotNull] this IAutoEntityDistributedEventSelectorList selectors,
Func<Type, bool> predicate)
@ -103,15 +116,15 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
{
Check.NotNull(selectors, nameof(selectors));
Check.NotNull(name, nameof(name));
return selectors.RemoveAll(s => s.Name == name).Count > 0;
}
public static bool IsMatch([NotNull] this IAutoEntityDistributedEventSelectorList selectors, Type entityType)
{
Check.NotNull(selectors, nameof(selectors));
return selectors.Any(s => s.Predicate(entityType));
}
}
}
}

Loading…
Cancel
Save