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();
}
}
この場合、オブジェクトコンストラクタをこのように動作させるためにマイクロソフトは何をしていますか?
明確にするために、メタデータは実際のコードではなくコードの表現ですか? – Kuhlk
はい、実際のコードではなく、型の定義だけです。 –
ありがとうございますこれは私の質問に答えます。 – Kuhlk