0

次のように作成されたリストがあります。コンピューター ゲームからの xml 情報のダウンロードを管理するサード パーティのラッパーを使用します。

List<EveAI.Live.Asset> lst_eveai_characterabc_assets = eve_api.GetCharacterAssets();

Asset のクラス定義は次のとおりです。

namespace EveAI.Live
{
  [TypeConverter(typeof(ExpandableObjectConverter))]
  public class Asset
  {
    public Asset();

    public ContainerType Container { get; set; }
    public List<Asset> Contents { get; set; }
    public double ContentsVolume { get; }
    public bool IsSingleton { get; set; }
    public long ItemID { get; set; }
    [Obsolete("Will be removed in a future version, use LocationStation or      
    LocationSolarsystem or LocationConquerableStation instead")]
    public Station Location { get; set; }
    public ConquerableStation LocationConquerableStation { get; set; }
    public int LocationID { get; set; }
    public SolarSystem LocationSolarsystem { get; set; }
    public Station LocationStation { get; set; }
    public long Quantity { get; set; }
    public int RawQuantity { get; set; }
    public ProductType Type { get; set; }
    public int TypeID { get; set; }

    public override string ToString();
  }
}

リスト lst_eveai_characterabc_assets をクラス AssetUniverseIDs を使用する新しいリストにコピーしたい - それはクラス EveAI.Live.Asset 何かを継承する:-

public class AssetUniverseIDs : EveAI.Live.Asset
{
  public Int32 stationID {get;set;}
  public Int32 stationTypeID { get; set; }
  public Int32 corporationID { get; set; }
  public Int32 solarSystemID { get; set; }
  public string solarSystemName { get; set; }
  public double security { get; set; }
  public string securityClass { get; set; }
  public Int32 constellationID { get; set; }
  public Int32 regionID { get; set; }
  public string regionName { get; set; }
  public string stationName { get; set; }
}

しかし、これまでのところ、クラス Assets を継承するクラス AssetUniverseIDs を使用する新しいリストに lst_eveai_characterabc_assets をコピーできません。どうすればこれを達成できますか。

4

1 に答える 1

1

ここでの最善の策は、コピー コンストラクターです。

public AssetUniverseIDs(EveAI.Live.Assett original)
{
     this.Container = original.Container;
     this.Contents = original.Contents;
     // ...
}

次に、次のようにアセットのリストから AssetUniverseID のリストを作成できます。

List<AssetUniverseIDs> newList = 
    lst_eveai_characterabc_assets.Select(a => new AssetUniverseIDs(a)).ToList();

AssetUniverseIDsから継承したい特別な理由はありますAssetか?Assetおそらく、プロパティの 1 つとしてを持つクラスを持つだけで十分でしょうか?

于 2013-01-23T18:53:20.603 に答える