【发布时间】:2021-04-09 20:03:00
【问题描述】:
我有一个类 BaseRequest,它有另一个类作为它的属性之一。该类有自己的一组属性,其中一些也是类,而其中一些类属性是类。如何初始化 ProductOptions-GroupsToRun 和 SelectionTargets 的 BaseRequest?
BaseRequest.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Redundent.Models
{
public class BaseRequest
{
public ProductOptions ProductOptions { get; set; }
public string RequestingSystem { get; set; }
public bool HasDeposit { get; set; }
public decimal? PurchasePrice { get; set; }
public decimal? PaymentAmount { get; set; }
}
}
ProductOptions.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Redundent.Models
{
public class ProductOptions
{
public GroupOption[] GroupsToRun { get; set; }
public string Requestor { get; set; }
public SelectionTargets SelectionTargets { get; set; }
public string Partner { get; set; }
}
}
GroupOption.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Redundent.Models
{
public class GroupOption
{
public TransportationType TransportationType { get; set; }
public RegistrationType Type { get; set; }
}
}
TransportationType 和 RegistrationType 是枚举。交通类型有汽车、飞机、船、巴士和 RegistrationType 有 Ticket、ID、Passport
SelectionTargets.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Redundent.Models
{
public class SelectionTargets
{
public PricingOptionTargets PricingOptionTargets { get; set; }
public ProductTargets ProductTargets { get; set; }
}
}
这就是我开始的...
var baseRequest = new BaseRequest()
{
ProductOptions = { GroupsToRun = {//not sure what to do here. Tried TransportationType.Car but got "does not contain a definition for 'Add' and no accessible extension method 'Add'}, Requestor = "Ford", SelectionTarget = {also not sure what to do here}, Partner =
"Heuwett B." },
};
【问题讨论】:
标签: c# class object inner-classes