I want to build set of methods:
I have this abstract:
public abstract Filter<T> Create(T type, string value);
public abstract IEnumerable<Filter<T>> Create(T type, IEnumerable<object> values);
And implementation:
public override Filter<DiscountFilterType> Create(DiscountFilterType type, string value)
=> new DiscountFilter {Type = type, Value = string.IsNullOrWhiteSpace(value) ? null : value};
public override IEnumerable<Filter<DiscountFilterType>> Create(DiscountFilterType type, IEnumerable<object> values)
=> values.Select(value => this.Create(type, value?.ToString())).ToList();
It looks good but if I want to do something like that:
var type = DiscountFilterType.CampaignStatus;
var values = new List<CampaignStatus>{
CampaignStatus.Active,
CampaignStatus.Accepted,
CampaignStatus.Supplement};
// Act
var result = sut.Create(ype, values);
And it trying to send a array to string method.
'CS1503 Argument 2: cannot convert from 'System.Collections.Generic.List<CampaignStatus>' to 'string'
What is going on? And if I want to do it this way:
public abstract Filter<T> Create(T type, object value);
public abstract IEnumerable<Filter<T>> Create(T type, IEnumerable<object> values);
How?
@Edit: I want to have method to create filter which takes: 1. one type, and one value 2. one type, multiple values and returns multiple filters 3. multiple types and multiple values and returns multiple filters
Type is always some of enum and value in the end should be as string but I don't want to cast values/arrays ToString before calling the method.