我试图通过行动代表一起构造,但得到以下错误:
委托“行动”不带参数0
代码:
public sealed class VariantProcessor
{
private string _myAppConnectionString { get; set; }
private readonly Action<Variant> _transform;
public Variant(string _myAppConnectionString,Action<Variant> transform)
{
_myAppConnectionString = _myAppConnectionString;
_transform = transform;
}
public void Process(Variant model)
{
try
{
_transform(model);
//version creation shared by both the derived types
}
catch (Exception)
{
}
}
}
public class AggregateCalculator : IVariantProcessor
{
private string _myAppConnectionString { get; set; }
public void Process(Variant model)
{
_myAppConnectionString = ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString;
new VariantProcessor( _myAppConnectionString,
() => Transform(model) //error
);
}
private void Transform(Variant model)
{
//logic on variant model
}
}
我想这样很好,但仍然没有运气:
new VariantProcessor(_myAppConnectionString,
Transform(model) // error
);
其实我有问题,理解这个语法() => Transform(model)
,因此,我没有得到什么问题在这里。
有人可以帮我找出什么问题吗?