2011-12-01 26 views
12

私はこの権利を呼んでいるのかどうかわかりませんが、クラス、メソッド、プロパティなどにドキュメントを追加したいと思っています。を知っています。どこから始めたらいいか分からない。C#のクラス、メソッド、プロパティなどにドキュメンテーションツールチップを追加するには?

クラス(またはメソッド、プロパティなど)をロールオーバーするたびに明確にするために、Visual Studioでツールチップを表示し、その特定のメソッドに関するドキュメントを表示します。

クラスMicrosoft.Phone.BackgroundAudio.BackgroundAudioPlayer
な再生、一時停止、早送りなどのオーディオ再生機能に背景のアクセスを提供し、巻き戻し。

これは何ですか、これをC#アプリケーションでどのように実装できますか?

答えて

26

あなたは///またはGhostDoc

編集を使用することができますXMLドキュメントまたはXML-docと呼ばれます。

XML-docは、3つのスラッシュ(///)を使用してクラス、フィールド、プロパティ、イベント、またはメソッドに対して実行され、その後にそのクラスまたはそのメンバーに関するXML形式のメタ情報が続きます。

VSは、XMLコメント用のIntelliSenseサポートを内蔵したこれらのコメントの生成と書式設定に役立ちますが、完全なXML-docテンプレートを自動的に生成するGhostDocという無料のツールがあります。ドキュメントのさまざまな要素の基本的な説明を推測しようとするケースもあります。ここで

は、XML文書の基本的な例です:

/// <summary> 
/// Defines the behavior of a class following the Repository pattern for data access 
/// with basic atomic operation control. 
/// </summary> 
/// <typeparam name="TRest">An interface derived from IDomainObject that describes domain objects 
/// that can be retrieved or saved by this Repository.</typeparam> 
public interface IRepository<TRest> : IDisposable where TRest : IDomainObject 
{ 
    /// <summary> 
    /// Begins a new unit of work to be performed atomically by the Repository. 
    /// </summary> 
    /// <returns>A token class representing the unit of work.</returns> 
    IUnitOfWork BeginUnitOfWork(); 

    /// <summary> 
    /// Commits all work performed under the specified unit of work. 
    /// </summary> 
    /// <param name="unitOfWork">The unit of work.</param> 
    void CommitUnitOfWork(IUnitOfWork unitOfWork); 

    /// <summary> 
    /// Rolls back the specified unit of work. 
    /// </summary> 
    /// <param name="unitOfWork">The unit of work.</param> 
    void RollBackUnitOfWork(IUnitOfWork unitOfWork); 

    /// <summary> 
    /// Saves the specified domain object to the data source controlled by the repository. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="domainObject">The domain object.</param> 
    /// <param name="unitOfWork">The unit of work.</param> 
    void Save<T>(T domainObject, IUnitOfWork unitOfWork) where T : class, TRest; 

    /// <summary> 
    /// Begins a Linq query for a specific object type, to be performed against the Repository's data source. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="unitOfWork">The unit of work.</param> 
    /// <returns>An IQueryable representing the query to be performed.</returns> 
    IQueryable<T> QueryFor<T>(IUnitOfWork unitOfWork) where T : class, TRest; 

    /// <summary> 
    /// Performs the specified Action using a new unit of work, with commits and rollbacks as necessary. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="func">The Action to perform. The lambda or named method must accept an IUnitOfWork as a parameter.</param> 
    /// <param name="commit">if set to <c>true</c>, commit the unit of work.</param> 
    void PerformInNewUnitOfWork<T>(Action<IUnitOfWork> func, bool commit = false); 

    /// <summary> 
    /// Performs the specified Func using a new unit of work, with commits and rollbacks as necessary. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="func">The function to evaluate. The lambda or named method must accept an IUnitOfWork as a parameter.</param> 
    /// <returns>A single object of the generic type, returned by the function.</returns> 
    /// <param name="commit">if set to <c>true</c>, commit the unit of work.</param> 
    T PerformInNewUnitOfWork<T>(Func<IUnitOfWork, T> func, bool commit = false) where T : class, TRest; 

    /// <summary> 
    /// Performs the specified Func using a new unit of work, with commits and rollbacks as necessary. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="func">The Function to evaluate. The lambda or named method must accept an IUnitOfWork as a parameter.</param> 
    /// <returns>An enumerable set of objects of the generic type, returned by the function.</returns> 
    /// <param name="commit">if set to <c>true</c>, commit the unit of work.</param> 
    IEnumerable<T> PerformInNewUnitOfWork<T>(Func<IUnitOfWork, IEnumerable<T>> func, bool commit = false) where T : class, TRest; 

    /// <summary> 
    /// Attaches the specified domain object to the current Unit of Work, allowing operations to be performed on it. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="domainObject">The domain object.</param> 
    /// <param name="unitOfWork">The unit of work.</param> 
    void Attach<T>(T domainObject, IUnitOfWork unitOfWork) where T : class, TRest; 

    /// <summary> 
    /// Detaches the specified domain object to the current Unit of Work. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="domainObject">The domain object.</param> 
    /// <param name="unitOfWork">The unit of work.</param> 
    void Detach<T>(T domainObject, IUnitOfWork unitOfWork) where T : class, TRest; 

    /// <summary> 
    /// Refreshes the specified collection of persistent elements with the most recent persisted data. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="elements">The list of elements to refresh.</param> 
    /// <param name="unitOfWork">The Unit of Work under which to perform the operation.</param> 
    void Refresh<T>(IList<T> elements, IUnitOfWork unitOfWork) where T : class, TRest; 

    /// <summary> 
    /// Deletes the specified domain object from the data store. 
    /// Usually performs a physical delete; logical deletes are most often done through updates. 
    /// </summary> 
    /// <typeparam name="T"></typeparam> 
    /// <param name="domainObject">The domain object to delete.</param> 
    /// <param name="unitOfWork">The unit of work under which to perform the operation.</param> 
    void Delete<T>(T domainObject, IUnitOfWork unitOfWork) where T : class, TRest; 
} 
+0

+1 for GhostDoc –

+0

@Shymep GhostDocは素晴らしいようです。私は確かにそれを試してみる必要があります。 – loyalpenguin

6

クラス、メソッド、またはプロパティのすぐ上に「///」と入力し、returnキーを押します。これにより、ドキュメントテンプレートが生成されます。

これはXML Documentation Commentsとして知られており、これに関する多くの情報がMSDNに掲載されています。あなたが参照している何秒

/// <summary> 
/// 
/// </summary> 
class B 
{ 

    /// <summary> 
    /// Initializes a new instance of the <see cref="B"/> class. 
    /// </summary> 
    public B() { } 

    /// <summary> 
    /// Gets or sets the property. 
    /// </summary> 
    /// <value> 
    /// The property. 
    /// </value> 
    public int Property { get; set; } 

    /// <summary> 
    /// Methods the specified obj. 
    /// </summary> 
    /// <param name="obj">The obj.</param> 
    public void Method(object obj) { } 
} 
+0

ちょうどあなたがメソッド/クラス/プロパティ/などを変更した場合、それは自動的にコメントを更新しないことを覚えておいてください。 APIドキュメントは間違いなく便利ですが、変更を加えるときに別の手動ステップを作成することを理解してください。 – David

+0

@competent_tech私はそれが何か単純でなければならないことを知っていました。私はそれが何のためか分からなかった。どうもありがとう。 – loyalpenguin

3

/// <summary> 
/// 
/// </summary> 
class A 
{ 
    /// <summary> 
    /// 
    /// </summary> 
    public A() { } 

    /// <summary> 
    /// 
    /// </summary> 
    public int Property { get; set; } 

    /// <summary> 
    /// 
    /// </summary> 
    /// <param name="obj"></param> 
    public void Method(object obj) { } 
} 

を得ることができます最初のケースでは

関連する問題