Skip to content

Commit

Permalink
feat: add IConverter
Browse files Browse the repository at this point in the history
BREAKING CHANGE: change namespace of IItemsProvider
BREAKING CHANGE: remove predicate parameter in ItemsFileProvider
  • Loading branch information
sandre58 committed May 23, 2024
1 parent dabdc9d commit 956b143
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
12 changes: 12 additions & 0 deletions src/MyNet.Utilities/Converters/IConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Stéphane ANDRE. All Right Reserved.
// See the LICENSE file in the project root for more information.

namespace MyNet.Utilities.Converters
{
internal interface IConverter<TFrom, TTo>
{
TTo Convert(TFrom item);

TFrom ConvertBack(TTo item);
}
}
9 changes: 0 additions & 9 deletions src/MyNet.Utilities/ICloneable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@

namespace MyNet.Utilities
{
/// <summary>
/// Supports copying, which creates a new instance of a class with the same values as an existing instance.
/// </summary>
public interface ICloneable<out T>
{
/// <summary>
/// Creates a deep copy of the current object including its properties.
/// </summary>
/// <returns>
/// A copy of the current object.
/// </returns>
T Clone();
}
}
6 changes: 0 additions & 6 deletions src/MyNet.Utilities/IModifiable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ namespace MyNet.Utilities
{
public interface IModifiable
{
/// <summary>
/// Reset IsModified value.
/// </summary>
void ResetIsModified();

/// <summary>
/// Gets if the object is modified.
/// </summary>
bool IsModified();
}
}
12 changes: 3 additions & 9 deletions src/MyNet.Utilities/IO/ItemsFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MyNet.Utilities.Providers;

namespace MyNet.Utilities.IO
{
public abstract class ItemsFileProvider<T> : IItemsProvider<T>
{
private readonly Func<T, bool> _predicate;

public string? Filename { get; private set; }

public IEnumerable<Exception> Exceptions { get; private set; } = [];

protected ItemsFileProvider(string? filename = null, Func<T, bool>? predicate = null)
{
SetFilename(filename.OrEmpty());
_predicate = predicate ?? new Func<T, bool>(x => true);
}
protected ItemsFileProvider(string? filename = null) => SetFilename(filename.OrEmpty());

public void SetFilename(string filename) => Filename = filename;

Expand All @@ -36,7 +30,7 @@ public IEnumerable<T> ProvideItems()
var (items, exceptions) = LoadItems(Filename);
Exceptions = exceptions;

return items.Where(_predicate);
return items;
}

protected abstract (IEnumerable<T> items, IEnumerable<Exception> exceptions) LoadItems(string filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Collections.Generic;

namespace MyNet.Utilities
namespace MyNet.Utilities.Providers
{
public interface IItemsProvider<out T>
{
Expand Down
3 changes: 3 additions & 0 deletions src/MyNet.Utilities/Providers/PredicateItemsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class PredicateItemsProvider<T> : IItemsProvider<T>
private readonly Func<T, bool> _predicate;
private readonly IItemsProvider<T> _itemsProvider;

public PredicateItemsProvider(IEnumerable<T> items, Func<T, bool> predicate)
: this(new ItemsProvider<T>(items), predicate) { }

public PredicateItemsProvider(IItemsProvider<T> provider, Func<T, bool> predicate)
{
_itemsProvider = provider;
Expand Down

0 comments on commit 956b143

Please sign in to comment.