2016-05-05 1 views
1

MVCアプリケーションには、メソッド本体がないコンストラクタを使用するいくつかのクラスがあります。たとえば、クラスの1つはActionResultクラスです。.net MCVはメソッドボディを持たないコンストラクタを使用しますが、これはどのように可能で、どのように複製できますか?

using System; 

namespace System.Web.Mvc 
{ 
    // Summary: 
    //  Encapsulates the result of an action method and is used to perform a framework-level 
    //  operation on behalf of the action method. 
    public abstract class ActionResult 
    { 
     // Summary: 
     //  Initializes a new instance of the System.Web.Mvc.ActionResult class. 
     protected ActionResult(); 

     // Summary: 
     //  Enables processing of the result of an action method by a custom type that 
     //  inherits from the System.Web.Mvc.ActionResult class. 
     // 
     // Parameters: 
     // context: 
     //  The context in which the result is executed. The context  information includes 
     //  the controller, HTTP content, request context, and route data. 
     public abstract void ExecuteResult(ControllerContext context); 
    } 
} 

このクラスコンストラクタにはメソッド本体がありません。 アプリケーションでコードを複製しようとすると、コンストラクタがメソッド本体を持つ必要があるとの予想されるエラーが発生します。

namespace ConsoleApplication1 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 


    public abstract class MyBase 
    { 
     protected MyBase(); 
    } 
} 

この場合、オブジェクトコンストラクタをこのように動作させるためにマイクロソフトは何をしていますか?

答えて

2

あなたは何を参照してください(参照ライブラリのように)あなたのプロジェクトの外側にあるタイプの定義に行くタイプ、含まれているメンバーとプレビューのメタデータです。

普通ののC#構文を使用して、これらのメンバーはすべて実際に実装されています(ソースの要約は除きます)。

のVisual Studioに拡張子を追加し、あなたが実際のコードを逆コンパイルして見ることができますリフレクターのようなツールがあります。

+0

明確にするために、メタデータは実際のコードではなくコードの表現ですか? – Kuhlk

+0

はい、実際のコードではなく、型の定義だけです。 –

+0

ありがとうございますこれは私の質問に答えます。 – Kuhlk

関連する問題