Where is the Type class? - vb.net

i just started learning vb.net.
But i couldnt find out where the System.Type class is.
I googled, but couldnt find any answers.
Here is what i did:
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
I changed the directory to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727> and supplied System.dll as argument
But i couldnt find Type class
So,where is the Type class??
If anything is wrong,ignore my ignorance.
Thank you.
Hello again,
i got another problem,this whole thing i mentioned above is about making a console app similar to java's javap.exe utility
if you give the class fullname as argument then it should print substantial info about the class.
the problem is - how do i know which .dll file to load depending upon the class name i give as input???(this is the reason why i expected System.Type would be in System.dll file)

I used ILSpy (free tool) to have a look. It is in the mscorlib.dll

Like Michal and Mr Lister stated it's in mscorlib.dll.
I found it a different way though, if take your code
Dim assobj as Type() = ass.GetTypes()
and right click on the word Type and press "Go To Definition" (shortcut key F12)
The default display is slightly different for VB.net & C#. (For me anyway)
For VB.Net:
You'll see the Object Browser, you can notice that the Type is a Member of System
If you click on System you'll notice that it is a member of mscorlib. If you click on mscorlib, then you can see where the DLL is actually stored.
If you are using C# then you will see:
#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
}
}

Related

Type 'Collection' is not defined vb BC30002

I am attempting to migrate a legacy vb.net application to .net standard and turn it into a nuget package. A good amount of it has been straight forward. I am currently hung up on this error caused by functions like this.
Public Property ErrorMessages As Collection
Get
ErrorMessages = _errorMessages
End Get
Set(value As Collection)
_errorMessages = value
End Set
End Property
If i import System.Collections.ObjectModelCollection(Of T) it is asking me for a type and i am unsure how to proceed. It turns my code into
Collection(Of,) and expects a second argument. Has anyone faced this before? Do i use a different import statement or how is this dealt with in vb now?
You should almost certainly replace Collection with Dictionary(Of TKey, TValue), using the dictionary type from the System.Collections.Generic namespace.
Once again, this requires you to fill in the genetic type arguments TKey and TValue with the actual types. You need to figure out from context which type fits the collection. The value of TKey is probably String since that’s the only key type VB6’ collections properly support. And given the name (ErrorMessages), TValue is probably String as well.

Compiler doesn't see CompareTo method in IComparable(Of T) object

I'm trying to apply the answer to Implementing generic IComparer in VB to my project by implementing an IComparable interface for a class in VB.NET. The section for the GenericComparer in that answer compiles fine, but the IComparable interface on my specific object won't get past the compiler.
Public Class RowAndRanking
Implements IComparable(Of RowAndRanking)
Public html As String
Public rank As Double
Public Function CompareTo(other As RowAndRanking) As Integer
Return Math.Round(Me.rank - other.rank)
End Function
End Class
The compiler keeps insisting that "Class 'RowAndRanking' must implement 'Function CompareTo(other As RowAndRanking) As Integer' for interface 'System.IComparable(Of RowAndRanking)'.", but looking at my code, I can see that method signature. Furthermore, if I go to where I'm trying to run a Sort on a List of these objects, I can type:
Dim row as RowAndRanking = new RowAndRanking
row.CompareTo(...
And Visual Studio's code complete picks up the method signature.
I've tried cleaning and rebuilding the project, but the issue remains. I've tried changing it to use a non-generic comparer solution, but the compiler still doesn't see the CompareTo method. This should be simple, but the compiler just doesn't see the function. Has this happened to anyone else? Is there something else that I can try?
Unlike C#, VB requires that you explicitly mark implementing methods.
Add
Implements IComparable(Of RowAndRanking).CompareTo

Implementing IPluginExtraMenus for FogBugz using VB.Net

We are attempting to create a FogBugz plugin & have started naturally with the Hello World example [Wiki 38].
We are using Visual Studio 2005 and VB.Net.
However, whenever we add "Implements IPluginExtraMenus" to our class AND implement the appropriate function, Visual Studio reports that
Class 'xxxx' must implement Function ExtrasMenuLinks() as UI.CNavMenuLink()
for interface FogCreek.FogBugz.Plugins.InterfacesIPluginExtrasMenu
Here is an example:
Public Class DaysRemaining
Inherits Plugin
Inherits IPluginPagedisplay
Inherits IPluginExtrasMenu
Public Function ExtrasMenuLinks() As UI.CNavMenuLink
dim vMenu as CNavMenuLink
vMenu = new CNavMenuLink("", "", "", "")
Return vMenu
End Function
End Class
Also, if we try and add an "Implements IPluginExtrasMenu.ExtrasMenuLinks" keyword in the function definition, Visual Studio reports that
'ExtrasMenuLinks' cannot implement 'ExtrasMenuLinks' because there is
no matching function on interface
FogCreek.FogBugz.Plugins.InterfacesIPluginExtrasMenu
We are importing all of the correct namespaces etc.
Any assistance will be greatly appreciated e.g. pointing where we have gone wrong, pointing us in the direction of other VB.Net examples, etc.
It looks like Visual Studio is complaining because interface expects ExtrasMenuLinks to return an array of UI.CNavMenuLink objects, whereas your implementation only returns a single UI.CNavMenuLink.
I believe the modification you need to make to match the interface is:
Public Function ExtrasMenuLinks() As UI.CNavMenuLink()
You'll also need to modify the function body to return an array.

How can I use an ITypeInfo pointer to get the name of the type?

Should be a simple question, but searching the documentation is driving me nuts. Suppose I have an ITypeInfo pointer for a coclass or an interface. How do I get the name of that class or interface?
Ok. It did turn out to be pretty simple. You just need to call the ITypeInfo.GetDocumentation method with the member id set to MEMBERID_NIL (−1). Like so:
CComBSTR typeName;
hr = typeInfo->GetDocumentation( MEMBERID_NIL, &typeName, NULL, NULL, NULL );
If you're programming in .NET, the above is conveniently performed for you by the Marshal.GetTypeInfoName method:
// using System.Runtime.InteropServices;
string typeName = Marshal.GetTypeInfoName(typeInfo);
The short answer: you can't using ITypeInfo. You can obtain the prog ID of class using the Win32 ProgIDFromCLSID API. In COM the name of the underlying C++, Visual Basic or .NET class implementing the COM interface or co-class is practically meaningless. Only interface IDs, class IDs and programmatic IDs have any significance beyond the source code of your co-class's implementation: only these can be used for activating COM objects using CoCreateInstance et al and runtime casting using QueryInterface.

vb.net Getting a reference to a class by its name

I'm trying to use reflection to get the instance of a class in vb.net. I have a class 'A' in my web project and to test it, i create a new aspx page and try to write the following:
Dim t as Type = Type.GetType("A")
This returns "Nothing". But if i do this:
Dim inst as A = new A()
Dim t as Type = inst.GetType()
t's type is "A"
So how come i can't get the type with GetType even if the name is exactly the same? It does works for things like System.Math though so i'm probably missing something as a newbie.
Two things:
You need to include the namespace of the type
If the type isn't in mscorlib or the currently executing assembly, you need to specify the assembly name as well (including version numbers and public key information if it's a strongly-named assembly).
So for instance, to get hold of System.Linq.Enumerable you'd need something like:
Type.GetType("System.Linq.Enumerable, System.Core, Version=4.0.0.0, " & _
"Culture=neutral, PublicKeyToken=b77a5c561934e089")