根据输入 C# 将数据存储到对象中
我必须根据输入将数据保存到不同的 C# 对象中。
根据“productChoice”的值,我的程序应该将数据保存到相应的类。
例如:
如果 ProductChoice = "auto" 则数据应设置为 AutoDataprefill 对象。
如果productChoice =“vehicle”,则数据应设置为VehicleMileage对象。
我的订单类别:
public class Order
{
public Products products {get;set;}
}
我的产品类:
public class Products
{
public productChoiceType products { get; set; }
}
我的产品选择类型类:
public class productChoiceType
{
public string productChoice { get; set; }
public AutoDataprefill auto_dataprefill { get; set; }
public VehicleMileage vehicle_mileage { get; set; }
public ClaimsDiscovery claims_discovery { get; set; }
public PropertyDataprefill property_dataprefill { get; set; }
public List productList { get; set; }
}
public class AutoDataprefill
{
public Parameter parameter { get; set; }
public Pnc pnc { get; set; }
public ProductReturnFormat format { get; set; }
public string primary_subject { get; set; } // Attribute // IDREF
}
public class VehicleMileage
{
public string usage { get; set; }
public VmrReportType report_type { get; set; }
public Vehicles vehicles { get; set; }
public string subject { get; set; } //Attribute // IDREF
}
这是我的代码,用于创建“订单”实例并将数据保存到相应的对象:
CLUEAuto.Personal.BusinessEntities.Order nwOrder = new CLUEAuto.Personal.BusinessEntities.Order
{
products = new CLUEAuto.Personal.BusinessEntities.Products
{
products = new CLUEAuto.Personal.BusinessEntities.productChoiceType
{
/* if (productChoice == "auto")
{Parameter = , Pnc = ,.... }
elseif (productChoice == "vehicle")
{usage = , reportType = , ....} */
???
}
}
}
I have to save data into different C# objects based on the input.
Based on the value of "productChoice" my program should save data to the corresponding class.
For example :
if productChoice = "auto" then the data shoud be set to AutoDataprefill object.
if productChoice = "vehicle" then the data shoud be set to VehicleMileage object.
My order class :
public class Order
{
public Products products {get;set;}
}
My Products class :
public class Products
{
public productChoiceType products { get; set; }
}
My productChoiceType class :
public class productChoiceType
{
public string productChoice { get; set; }
public AutoDataprefill auto_dataprefill { get; set; }
public VehicleMileage vehicle_mileage { get; set; }
public ClaimsDiscovery claims_discovery { get; set; }
public PropertyDataprefill property_dataprefill { get; set; }
public List productList { get; set; }
}
public class AutoDataprefill
{
public Parameter parameter { get; set; }
public Pnc pnc { get; set; }
public ProductReturnFormat format { get; set; }
public string primary_subject { get; set; } // Attribute // IDREF
}
public class VehicleMileage
{
public string usage { get; set; }
public VmrReportType report_type { get; set; }
public Vehicles vehicles { get; set; }
public string subject { get; set; } //Attribute // IDREF
}
Here is my code to create an instance of "order" and save data to corresponding objects:
CLUEAuto.Personal.BusinessEntities.Order nwOrder = new CLUEAuto.Personal.BusinessEntities.Order
{
products = new CLUEAuto.Personal.BusinessEntities.Products
{
products = new CLUEAuto.Personal.BusinessEntities.productChoiceType
{
/* if (productChoice == "auto")
{Parameter = , Pnc = ,.... }
elseif (productChoice == "vehicle")
{usage = , reportType = , ....} */
???
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您以这种方式处理对象的创建,也许会更容易:
Maybe it would be easier if you handle the creation of your objects this way: