2017-08-01 4 views
-2

私は、アクセスしようとしているオブジェクトの構造を持っています。私はそれがすべて最初に働くことができることを確認するために指示のエイリアスを使用していませんが、私のforeachループは別のオブジェクトに含まれているオブジェクトのリストにアクセスできません。ここでエラーCS1061同じ名前空間内の別のオブジェクト内のオブジェクトリストにアクセスする場合

は誤りです: CS1061「リスト」「資格」の定義が含まれておらず、型「リスト」の無い拡張メソッド「資格」受け入れて最初の引数は(あなたがusingディレクティブが欠落しているが見つかりませんでしたまたはアセンブリ参照エラーが「資格」には、第二foreachループ(トリガされる場合)

そして、ここ)である:

foreach (EntitlementGroup eg in report.product.context.productDetails.entitlementgroup) 
      { 
       writer.WriteStartElement("EntitlementGroup"); 
       foreach (Entitlement e in report.product.context.productDetails.entitlementgroup.entitlements) 
        { 
          //do stuff} 
        } 
       } 

エラーが資格に、第二のforeachループから来ています。

EntitlementGroupクラスが他のすべてのオブジェクトを見ることができるように私には思える

using System.Linq; 
namespace XMLWriter 
{ 
    public class Entitlement 
    { 
     public string primaryIndicator { get; set; } 
     public string includeExcludeIndicator { get; set; } 
     public AudienceTypeEntitlement audienceTypeEntitlement { get; set; } 
     public Entitlement(string primaryIndicator, string includeExcludeIndicator, AudienceTypeEntitlement audienceTypeEntitlement) 
     { 
      this.primaryIndicator = primaryIndicator; 
      this.includeExcludeIndicator = includeExcludeIndicator; 
      this.audienceTypeEntitlement = audienceTypeEntitlement; 
     } 
    } 
} 

(productdetails、コンテキスト

using System.Collections.Generic; 
using System.Linq; 

namespace XMLWriter 
{ 
    public class EntitlementGroup 
    { 

     public List<Entitlement> entitlements { get; set; } 
     public EntitlementGroup(List<Entitlement> entitlements) 
     { 
      this.entitlements = entitlements; 
     } 
    } 
} 

資格:病気は、資格とここentitlementgroupクラスを置きます等)は、以前のメソッドの実装に基づいてちょうど良い。

+0

'report.product.context.productDetails.entitlementgroup'のタイプは何であるべきか?それは 'EntitlementGroup'ではなく、リストです。リストには「資格」というプロパティはありません。 – Amy

+1

ネストされたループ内で 'e'変数の属性にアクセスする必要があります。ネストされたループは' eg'変数を使用する必要があります – ironstone13

+1

@Willデバッグはコンパイルが成功した後に行われます。このスニペットはコンパイルされません。 –

答えて

2

これは

foreach (EntitlementGroup eg in report.product.context.productDetails.entitlementgroup) 
{ 
    writer.WriteStartElement("EntitlementGroup"); 
    foreach (Entitlement e in eg.entitlements) 
     { 
       //do stuff} 
     } 
    } 
関連する問題