Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .net MCV使用没有方法体的构造函数,这是怎么可能的,怎么可以复制?_C#_.net_Frameworks - Fatal编程技术网

C# .net MCV使用没有方法体的构造函数,这是怎么可能的,怎么可以复制?

C# .net MCV使用没有方法体的构造函数,这是怎么可能的,怎么可以复制?,c#,.net,frameworks,C#,.net,Frameworks,在MVC应用程序中,有几个类使用构造函数而没有方法体。例如,其中一个类是ActionResult类: 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

在MVC应用程序中,有几个类使用构造函数而没有方法体。例如,其中一个类是ActionResult类:

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();
    }
}

在这种情况下,Microsoft是如何使对象构造函数以这种方式工作的?

当您转到项目外部(如在引用库中)类型的定义时,您看到的是该类型的元数据,即包含的成员的预览

所有这些成员实际上都是使用常规C#语法实现的(cource摘要除外)


有像Reflector这样的工具,可以向Visual Studio添加扩展,并允许您反编译和查看实际代码。

因此,为了澄清,元数据是代码的表示,而不是实际代码?是的,您看到的不是真正的代码,只是类型的定义。好的,谢谢,这回答了我的问题。