在包含数组的接口上使用nServiceBus'cre​​ateInstance - 如何实例化数组?

时间:2013-11-01 20:35:47

标签: nservicebus

我的事件定义如下:

public interface IClass
{
     DateTime EffectiveDate { get; set; }
     IChild[] Children { get; set; }
}

public interface IChild
{
     string From { get; set; }
     string To { get; set; }
     decimal ADecimal { get; set; }
}

我正在尝试使用以下语法

bus.send<IClass>(class=> 
{
    class.EffeciveDate = DateTime.now;
    class.Children = //Not sure what to do here
}

如何实例化数组并填充子对象?

1 个答案:

答案 0 :(得分:0)

Child并不需要成为在事件中使用createinstance的接口。

你试过了吗?

public interface IClass
{
     DateTime EffectiveDate { get; set; }
     Child[] Children { get; set; }
}

public class Child
{
     string From { get; set; }
     string To { get; set; }
     decimal ADecimal { get; set; }
}

然后

Child someArray = Child[] { ... some items ... }    

bus.send<IClass>(class=> 
{
    class.EffeciveDate = DateTime.Now;
    class.Children = someArray;
}