Bodyless constructor in non-abstract C# class

c# constructor abstract-class

364 просмотра

2 ответа

I'm trying to understand the following class provided in the MVC framework; it seems like the class should be abstract, but it is not, and yet this class compiles. Is the class actually abstract despite the missing "abstract" keyword? What am I missing here?

namespace Microsoft.AspNet.Identity.EntityFramework
    public class IdentityUser : IUser
        public IdentityUser();
        public IdentityUser(string userName);

        public virtual ICollection<IdentityUserClaim> Claims { get; }
        public virtual string Id { get; set; }
        public virtual ICollection<IdentityUserLogin> Logins { get; }
        public virtual string PasswordHash { get; set; }
        public virtual ICollection<IdentityUserRole> Roles { get; }
        public virtual string SecurityStamp { get; set; }
        public virtual string UserName { get; set; }


Lesson learned: if there is no source provided for a binary, using "Go To Definition" in Visual Studio will provide something that looks mostly like source code... which is different than using "Open Declaration" in Eclipse, which will show you something that really doesn't look like source.

Автор: Mike Godin Источник Размещён: 12.11.2019 10:00

Ответы (2)

10 плюса


This is a Microsoft's class which I presume you retrieved the code for by "Go to Definition" context menu in Visual Studio. This code is auto generated by reflecting over the type, and only is meant to show declarations and not the implementation content. If you use .NET Refector or dotReflect tools, then you'll see body of the implementation.

Автор: LB2 Размещён: 14.03.2014 03:43

2 плюса

What you are missing is that you are not actually looking at the source code for the class. It is part of ASP.NET, documented here. The source code is kept in Redmond Washington, out of reach of your machine and not part of the .NET Reference Source.

What you got is an auto-generated document, produced from the metadata in the Microsoft.AspNet.Identity.EntityFramework.dll assembly. Which only contains the class declaration, the code was compiled into MSIL by the C# compiler. You'd need a good decompiler to see a resemblance of that code, Reflector and ILSpy are popular.

Be careful when you use Go To Definition in Visual Studio. You only see real source code when the IDE can find it.

Автор: Hans Passant Размещён: 14.03.2014 03:50
Вопросы из категории :