Skip to content

Commit

Permalink
Merge pull request #89 from neuroglia-io/fix-event-sourcing
Browse files Browse the repository at this point in the history
Fixed the PluginTypeFilter to allow specifiying the type of match to perform, which now defaults to 'any'
  • Loading branch information
cdavernas authored Apr 10, 2024
2 parents 7d032b7 + bcb84c5 commit 6926595
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Neuroglia.Plugins/PluginTypeFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ public class PluginTypeFilter
: IPluginTypeFilter
{

/// <summary>
/// Gets/sets the type of match the filter should perform on its criteria
/// </summary>
public PluginTypeFilterMatch Match { get; set; } = PluginTypeFilterMatch.Any;

/// <summary>
/// Gets/sets a list containing the filter's filtering criteria
/// </summary>
public List<PluginTypeFilterCriterion> Criteria { get; set; } = new();
public List<PluginTypeFilterCriterion> Criteria { get; set; } = [];

/// <summary>
/// Determines whether or not to filter the specified type
/// </summary>
/// <param name="type">The type to check</param>
/// <param name="metadataLoadContext">The <see cref="MetadataLoadContext"/> to use, if any</param>
/// <returns>A boolean indicating whether or not to filter the specified type</returns>
public virtual bool Filters(Type type, MetadataLoadContext? metadataLoadContext = null) => Criteria.All(c => c.IsMetBy(type, metadataLoadContext));
public virtual bool Filters(Type type, MetadataLoadContext? metadataLoadContext = null) => this.Match == PluginTypeFilterMatch.Any ? this.Criteria.Any(c => c.IsMetBy(type, metadataLoadContext)) : this.Criteria.All(c => c.IsMetBy(type, metadataLoadContext));

}

33 changes: 33 additions & 0 deletions src/Neuroglia.Plugins/PluginTypeFilterMatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright © 2021-Present Neuroglia SRL. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Runtime.Serialization;

namespace Neuroglia.Plugins;

/// <summary>
/// Enumerates all plugin filter criteria match types
/// </summary>
public enum PluginTypeFilterMatch
{
/// <summary>
/// Indicates that the plugin should many all criteria
/// </summary>
[EnumMember(Value = "all")]
All,
/// <summary>
/// Indicates that the plugin should many any criteria
/// </summary>
[EnumMember(Value = "any")]
Any
}

0 comments on commit 6926595

Please sign in to comment.