I have an Interface and an Abstract class with its derived one:
public interface IIndicator<TInput, TOutput> { }
public abstract class Indicator<TInput, TOutput> : IIndicator<TInput, TOutput> {
public abstract TOutput Calculate(TInput input);
}
public class MyIndicator : Indicator<Decimal, Decimal?> {
public MyIndicator(IEnumerable<Decimal> inputs) {
// Code using base.Calculate and inputs
}
public MyIndicator(IEnumerable<Decimal> inputs, Func<TMapper, Decimal> mapper) {
// Code using base.Calculate, inputs and mapper
}
public override TOutput Calculate(TInput input) {
// Implementation of Calculate
}
}
The problem is that TMapper is not defined in the contructor:
public MyIndicator(IEnumerable<Decimal> inputs, Func<TMapper, Decimal> mapper, Int32 period)
I would like to use MyIndicator as:
MyIndicator indicator = new MyIndicator(inputs, x => x.Id)
Instead of:
MyIndicator<MyClass> indicator = new MyIndicator<MyClass>(inputs, x => x.Id)
Where MyClass would be something like:
public class MyClass {
public Int32 Id { get; set; }
}
Is this possible?
MyClassinstead ofTMapperbecause there's nothing else it can be with the syntax you want.MyClassand should appear before the Mapper lambda.