2012-01-18 15 views
0

上のアレイの種類は、私はA1を入力しマッピングし、既存のマップを持って、私はタイプExpression<Func<A2, B2, C2, ..., Z2>>ネストされたビル、ジェネリック、およびランタイム

の式にタイプ

Expression<Func<A1, B1, C1, ..., Z1>>の表現に変換することができますExpressionConverterを構築していますA2B1~B2,C1~C2などと入力してください。 シンプルな地図は簡単に使えます。私は私がA1[](一般的なケースを見ると、直接、私は動的にA2[]のようなものを配列型を構築する必要がありA1A2にマッピングするので

private Type GetMappingType(Type type) 
{ 
    var types = _mappingFinder.FindTypesFor(type).ToArray(); 
    if (types.Length == 0) 
    { 
     if (type.IsNested) 
     { 
      var nestedTypes = type.GetNestedTypes(); 
      var mappedNestedTypes = nestedTypes.Select(this.GetMappingType).ToArray();    
      //TODO: return the nested type   
     } 
     if (type.HasElementType) 
     { 
      var mappedElementType = this.GetMappingType(type.GetElementType()); 
      //TODO: return the right container type with the mappedElementType 
     } 
     if (type.IsGenericType) 
     { 
      var genericTypes = type.GetGenericArguments(); 
      var mappedGenericTypes = genericTypes.Select(this.GetMappingType).ToArray();      
      //TODO: return generictype with the mappedGenericTypes as arguments 
     } 
     return type; 
    } 
    if (types.Length == 1) 
     return _types.Contains(types[0]) ? type : types[0]; 

    throw new Exception("Too many mapped types for " + type); 
}   

問題の例は、//TODO でマークされている:、Func<A2>に... ) 誰かが正しい方向/ドキュメントを教えてくれますか?

答えて

1

アレイの場合:ジェネリック医薬品については mappedElementType.MakeArrayType();

return type.GetGenericTypeDefinition().MakeGenericType(mappedGenericTypes);

しかし、私は自分で問題に直面したことがないので、おそらく、ネストされたタイプのためのポイントを逃しました。

関連する問題