2017-06-05 5 views
1

を使用して、2つの異なるオブジェクトのcommmonプロパティを取得します。しかし、私はJoinの近くに正しい構文を提供することができません。これは私のコードです。 、私はPropertyInfo[]の代わりに異なるコレクションのタイプHashSet<string>を示唆Iは<em>配列</em>に2つの異なるクラスのオブジェクトから<em>共通プロパティ</em>(<em>同じ名前</em>を有する即ち.propertiesファイル)を取得する必要がC#の

 PropertyInfo[] objAllProps = SourceInstance.GetType().GetProperties(); 
     PropertyInfo[] objAllProps_Target = TargetInstance.GetType().GetProperties(); 

     PropertyInfo[] CommonProperties = 
       from allprops in objAllProps join 
        allprop_target in objAllProps_Target on 
         allprops.Name.Equals(allprop_target) 
      select new PropertyInfo[] { 
         allprop_target, 
        } 
      .ToArray<PropertyInfo>(); 

答えて

4

助けてください:

HashSet<string> NamesToFind = new HashSet<string>(SourceInstance 
    .GetType() 
    .GetProperties() 
    .Select(property => property.Name)); 

    // Common properties: properties of TargetInstance such that 
    // there's a property of SourceInstance with the same name 
    PropertyInfo[] CommonProperties = TargetInstance 
    .GetType() 
    .GetProperties() 
    .Where(property => NamesToFind.Contains(property.Name)) 
    .ToArray(); 
+0

TX dmitry..it仕事をしてくれた:-)。 –

関連する問題

 関連する問題