0

入力に基づいて、データを別の C# オブジェクトに保存する必要があります。

「productChoice」の値に基づいて、私のプログラムは対応するクラスにデータを保存する必要があります。

例えば ​​:

productChoice = "auto" の場合、データは AutoDataprefill オブジェクトに設定する必要があります。

productChoice = "vehicle" の場合、データは VehicleMileage オブジェクトに設定する必要があります。

私の注文クラス:

    public class Order
    {
       public Products  products {get;set;}
    }
 

私の製品クラス:

  public class Products
    {
       public productChoiceType products { get; set; }
    }
  

私のproductChoiceTypeクラス:

   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 = , ....}  */

                                   ???
                }
             }
        }   
4

1 に答える 1

1

この方法でオブジェクトの作成を処理すると、おそらく簡単になります。

string productChoice = "auto";
Order nwOrder = new Order();
Products nwProducts = new Products();
nwOrder.products = nwProducts;
productChoiceType nwPCT = new productChoiceType();
if(productChoice == "auto") {   
  AutoDataprefill adp = new AutoDataprefill();
  //adp.Parameter = ...
  //adp.Pnc = ...
  nwPCT.auto_dataprefill = adp;
}
else if (productChoice == "vehicle")
{
  // etc...
}
nwProducts.products = nwPCT;
于 2010-11-17T23:08:59.423 に答える