作者:VB.NET开发
项目:Syste
Class TestFullName
Public Shared Sub Main()
Dim t As Type = GetType(Array)
Console.WriteLine("The full name of the Array type is {0}.", t.FullName)
End Sub
End Class
作者:VB.NET开发
项目:Syste
' 导入命名空间
Imports System.Collections.Generic
Imports System.Globalization
Module Example
Public Sub Main()
Dim t As Type = GetType(String)
ShowTypeInfo(t)
t = GetType(List(Of))
ShowTypeInfo(t)
Dim list As New List(Of String)()
t = list.GetType()
ShowTypeInfo(t)
Dim v As Object = 12
t = v.GetType()
ShowTypeInfo(t)
t = GetType(IFormatProvider)
ShowTypeInfo(t)
Dim ifmt As IFormatProvider = NumberFormatInfo.CurrentInfo
t = ifmt.GetType()
ShowTypeInfo(t)
End Sub
Private Sub ShowTypeInfo(t As Type)
Console.WriteLine($"Name: {t.Name}")
Console.WriteLine($"Full Name: {t.FullName}")
Console.WriteLine($"ToString: {t}")
Console.WriteLine($"Assembly Qualified Name: {t.AssemblyQualifiedName}")
Console.WriteLine()
End Sub
End Module
作者:VB.NET开发
项目:Syste
' 导入命名空间
Imports System.Collections.Generic
Module Example
Public Sub Main()
Dim t As Type = GetType(List(Of))
Console.WriteLine(t.FullName)
Console.WriteLine()
Dim list As New List(Of String)()
t = list.GetType()
Console.WriteLine(t.FullName)
End Sub
End Module
作者:VB.NET开发
项目:Syste
' 导入命名空间
Imports System.Reflection
Module Example
Public Sub Main()
Dim t As Type = GetType(Nullable(Of ))
Console.WriteLine(t.FullName)
If t.IsGenericType Then
Console.Write(" Generic Type Parameters: ")
Dim gtArgs As Type() = t.GetGenericArguments
For ctr As Integer = 0 To gtArgs.Length - 1
Console.WriteLine(If(gtArgs(ctr).FullName,
"(unassigned) " + gtArgs(ctr).ToString()))
If ctr < gtArgs.Length - 1 Then Console.Write(", ")
Next
Console.WriteLine()
End If
End Sub
End Module
作者:VB.NET开发
项目:Syste
' 导入命名空间
Imports System.Reflection
Public Class GenericType1(Of T)
Public Sub Display(elements As T())
End Sub
' Visual Basic does not support pointer types.
Public Sub HandleT(obj As T)
End Sub
Public Function ChangeValue(ByRef arg As T) As Boolean
Return True
End Function
End Class
Module Example
Public Sub Main()
Dim t As Type = GetType(GenericType1(Of ))
Console.WriteLine("Type Name: {0}", t.FullName)
Dim methods() As MethodInfo = t.GetMethods(BindingFlags.Instance Or
BindingFlags.DeclaredOnly Or
BindingFlags.Public)
For Each method In methods
Console.WriteLine(" Method: {0}", method.Name)
' Get method parameters.
Dim param As ParameterInfo = method.GetParameters()(0)
Dim paramType As Type = param.ParameterType
If method.Name = "HandleT" Then
paramType = paramType.MakePointerType()
End If
Console.WriteLine(" Parameter: {0}",
If(paramType.FullName,
paramType.ToString() + " (unassigned)"))
Next
End Sub
End Module
作者:VB.NET开发
项目:Syste
' 导入命名空间
Imports System.Reflection
Public Class Base(Of T)
End Class
Public Class Derived(Of T) : Inherits Base(Of T)
End Class
Module Example
Public Sub Main()
Dim t As Type = GetType(Derived(Of ))
Console.WriteLine("Generic Class: {0}", t.FullName)
Console.WriteLine(" Contains Generic Paramters: {0}",
t.ContainsGenericParameters)
Console.WriteLine(" Generic Type Definition: {0}",
t.IsGenericTypeDefinition)
Console.WriteLine()
Dim baseType As Type = t.BaseType
Console.WriteLine("Its Base Class: {0}",
If(baseType.FullName,
"(unassigned) " + baseType.ToString()))
Console.WriteLine(" Contains Generic Paramters: {0}",
baseType.ContainsGenericParameters)
Console.WriteLine(" Generic Type Definition: {0}",
baseType.IsGenericTypeDefinition)
Console.WriteLine(" Full Name: {0}",
baseType.GetGenericTypeDefinition().FullName)
Console.WriteLine()
t = GetType(Base(Of ))
Console.WriteLine("Generic Class: {0}", t.FullName)
Console.WriteLine(" Contains Generic Paramters: {0}",
t.ContainsGenericParameters)
Console.WriteLine(" Generic Type Definition: {0}",
t.IsGenericTypeDefinition)
End Sub
End Module