4

我刚开始学习vb.net。但我找不到 System.Type 类在哪里。我用谷歌搜索,但找不到任何答案。这是我所做的:

Module m
Sub Main(ByVal e as String())
Dim ass as Assembly = Assembly.LoadFrom(e(0))
Dim assobj as Type() = ass.GetTypes()
For Each m As Type In assobj
Console.WriteLine(m.Name)
next

我将目录更改为 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727> 并提供 System.dll 作为参数但我找不到 Type 类

那么,Type 类在哪里?

如果有什么不对的,请忽略我的无知。谢谢你。

再次您好,我遇到了另一个问题,我上面提到的整个事情是关于制作一个类似于 java 的 javap.exe 实用程序的控制台应用程序

如果你给类全名作为参数,那么它应该打印关于类的大量信息。

问题是 - 我如何知道要加载哪个 .dll 文件取决于我作为输入提供的类名???(这就是我期望 System.Type 会在 System.dll 文件中的原因)

4

2 回答 2

2

我用ILSpy(免费工具)来看看。它在 mscorlib.dll 中

于 2012-04-26T15:03:38.000 回答
2

就像 Michal 和 Lister 先生所说的那样,它位于 mscorlib.dll 中。

我发现它的方式不同,如果拿你的代码

Dim assobj as Type() = ass.GetTypes()

并右键单击“类型”并按“转到定义”(快捷键 F12)

VB.net 和 C# 的默认显示略有不同。(无论如何对我来说)

对于 VB.Net:

你会看到对象浏览器,你会注意到类型是系统的成员
对象浏览器中的类型定义

如果单击 System,您会注意到它是 mscorlib 的成员。如果单击 mscorlib,则可以看到 DLL 的实际存储位置。

对象浏览器中的系统定义


如果您使用的是 C#,那么您将看到:

#region Assembly mscorlib.dll, v4.0.30319
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll
#endregion

using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;

namespace System
{
    // Summary:
    //     Represents type declarations: class types, interface types, array types,
    //     value types, enumeration types, type parameters, generic type definitions,
    //     and open or closed constructed generic types.
    [Serializable]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(_Type))]
    [ComVisible(true)]
    public abstract class Type : MemberInfo, _Type, IReflect
    {
        //snip
    }
}
于 2012-04-26T15:30:18.170 回答