本文整理汇总了VB.NET中System.Reflection.MethodBase.GetCurrentMethod方法的典型用法代码示例。如果您正苦于以下问题:VB.NET MethodBase.GetCurrentMethod方法的具体用法?VB.NET MethodBase.GetCurrentMethod怎么用?VB.NET MethodBase.GetCurrentMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了MethodBase.GetCurrentMethod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Reflection
Module Example
Public Sub Main()
Dim t As New TestClass()
Console.WriteLine(t.GetValue())
t.Value = 10
Console.WriteLine(t.Value)
Console.WriteLine()
Dim tg As New Test(Of Integer)(200)
Console.WriteLine(tg.GetValue())
Dim b = tg.ConvertValue(Of Byte)()
Console.WriteLine("{0} -> {1} ({2})", tg.GetValue().GetType().Name,
b, b.GetType().Name)
End Sub
End Module
Public Class TestClass
Private _value As Nullable(Of Integer)
Public Sub New()
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
End Sub
Public Sub New(value As Integer)
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
_value = value
End Sub
Public Property Value As Integer
Get
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
Return _value.GetValueOrDefault()
End Get
Set
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
_value = value
End Set
End Property
Public Function GetValue() As Integer
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
Return Me.Value
End Function
End Class
Public Class Test(Of T)
Private value As T
Public Sub New(value As T)
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
Me.value = value
End Sub
Public Function GetValue() As T
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
Return value
End Function
Public Function ConvertValue(Of Y)() As Y
Dim m As MethodBase = MethodBase.GetCurrentMethod()
Console.WriteLine(" Executing {0}.{1}",
m.ReflectedType.Name, m.Name)
Console.Write(" Generic method: {0}, definition: {1}, Args: ",
m.IsGenericMethod, m.IsGenericMethodDefinition)
If m.IsGenericMethod Then
For Each arg In m.GetGenericArguments()
Console.Write("{0} ", arg.Name)
Next
End If
Console.WriteLine()
Try
Return CType(Convert.ChangeType(value, GetType(Y)), Y)
Catch e As OverflowException
Throw
Catch e As InvalidCastException
Throw
End Try
End Function
End Class
开发者ID:VB.NET开发者,项目名称:System.Reflection,代码行数:98,代码来源:MethodBase.GetCurrentMethod 输出:
Executing TestClass..ctor
Executing TestClass.GetValue
Executing TestClass.get_Value
0
Executing TestClass.set_Value
Executing TestClass.get_Value
10
Executing Test`1..ctor
Executing Test`1.GetValue
200
Executing Test`1.ConvertValue
Generic method: True, definition: True, Args: Y
Executing Test`1.GetValue
Int32 -> 200 (Byte)
注:本文中的System.Reflection.MethodBase.GetCurrentMethod方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论