2016-07-23 4 views
0

Web APIアプリケーション用のVisual Studio 2013自動生成XMLドキュメントを使用していますが、リスト<を継承するビジネスオブジェクトのプロパティを除いては正常に動作しています。私がそれらから得るのは、「オブジェクトのコレクション」です。一例として、VSはWebAPI、プロパティドキュメントのヘルプページを生成しました

が、ここでOrderLineCollectionプロパティが含まれているOrderオブジェクトです:

public class Order 
{ 
    public OrderLineCollection Lines { get; set; } 
} 

public class OrderLine 
{ 
    public string OrderNo { get; set; } 
} 

public class OrderLineCollection : List<OrderLine> 
{ 
    public void ReadFromServer(string orderNo) 
    {} 
} 

Orderオブジェクト用に生成されたドキュメントは唯一で、行プロパティのタイプ列に「オブジェクトのコレクション」を持っていますOrderLineオブジェクトへのリンクはありません。

私が代わりにこのような行プロパティを定義する場合、それは(オーダーラインがハイパーリンクに=私は、タイプ欄に「オーダーラインのコレクション」を取得)作品:

public class Order 
{ 
    public List<OrderLine> Lines { get; set; } 
} 

しかし、私はできるようにしたいと思います上記のようにOrderLineCollectionクラスを使用して、そこにコレクション固有のロジックを保持できるようにします。 XML文書でLinesプロパティの "OrderLine(ハイパーリンク)のコレクション"と言うだけでいいです。

これを行う簡単な方法はありますか?あなたのWeb APIプロジェクトで

答えて

0

、ヘルプページのモデルタイプの名前を生成するための責任があるクラスのコードファイルを開きます。

{MyProjectと} /エリア/ HelpPage/ModelDescriptions/ModelDescriptionGenerator.cs

の方法に進みます。

public ModelDescription GetOrCreateModelDescription(Type modelType) 

次のコードを行きますその後、

if (modelType.IsEnum) 
{ 
    return GenerateEnumTypeModelDescription(modelType); 
} 

と右のそれの後に次のコードを入力します:メソッド内

// Force Web API to generate help page model type names like "Collection of {MyType}" instead of "Collection of Object". 
if (!modelType.IsGenericType        // Model type must not be a generic type. 
    && modelType.BaseType != null       // Model type must have a base type (i.e. the model type is a derived type). 
    && modelType.BaseType.IsGenericType      // Model type base type must be a generic type. 
    && typeof(IList).IsAssignableFrom(modelType.BaseType)) // Model type base type must implement the IList interface (you can replace "IList" with "IEnumerable" to handle more general collection types). 
{ 
    // Set the model type variable to the model type base type and the rest of the method will know what to do. 
    modelType = modelType.BaseType; 

} 

私はこのことができます願っています!

関連する問題