我如何访问Linq中“付费”类中的PayTime字段

时间:2018-10-24 06:29:26

标签: c# linq design-patterns

我们使用模式策略实现了一个名为FactorStateBase的字段。该字段的默认值为PendingFactorState。我们希望访问处于付费状态及其日期在特定时间间隔内的所有因素。当实际完成付款并将新类别分配给状态字段时,此付款时间间隔将在PaidFactorState内部“重新设置”。

我的问题是如何访问Linq中“付费”类中的付款日期字段?

谢谢

   public class Factor : AggregateRoot<long>, IHasCreationTime
{

    public Factor(long id, long orderId, decimal price)
    {
        Id = id;
        Price = price;
        OrderId = orderId;
       FactorStateBase = new PendingFactorState(Guid.NewGuid());
    }
    public long OrderId { get; private set; }
    public decimal Price { get; private set; }
    public virtual FactorStateBase FactorStateBase { get; private set; }
    public void PayFactor(Guid id, string messageNumber, Guid paymentId, string transactionCode)
    {
      FactorStateBase = new PaidFactorState(id, messageNumber, paymentId, transactionCode);
    }

}
public abstract class FactorStateBase : Entity
{
    protected FactorStateBase(Guid id)
    {
        Id = id;
    }
}
public class PaidFactorState : FactorStateBase
{
    public PaidFactorState(Guid id, string messageNumber, Guid paymentId, string transactionCode) : base(id)
    {
        PayTime = DateTime.Now;
        MessageNumber = messageNumber;
        PaymentId = paymentId;
        TransactionCode = transactionCode;
    }
    public DateTime PayTime { get; private set; }
    public string MessageNumber { get; private set; }
    public Guid PaymentId { get; private set; }
    public string TransactionCode { get; private set; }

}

1 个答案:

答案 0 :(得分:1)

[
  {
    "Inputs": [
      {
        "Input": "ABC"
      },
      {
        "Input": "DEF "
      },
      {
        "Input": "GHI"
      }
    ]
  }
]

您可以为此代码使用public partial class InputArray { [JsonProperty("Inputs")] public List<InputObject> Inputs { get; set; } } public partial class InputObject { [JsonProperty("Input")] public string Input { get; set; } } public static void LoadJson() { using (StreamReader r = new StreamReader("input.json")) { var json = r.ReadToEnd(); var items = JsonConvert.DeserializeObject<List<InputObject>>(json); foreach (var item in items) { Debug.WriteLine(item.Input); } } } ,对于付费文件,可以使用PendingFactorState字段