컨트롤 이름으로 컨트롤 객체를 반환 받을 수 있다.


소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
Public Module ControlSelectorExtension
    <System.Runtime.CompilerServices.Extension()>
    Public Function FindByName(Of T)(targetClass As Object, name As String) As T
        Dim info As Reflection.PropertyInfo = targetClass.GetType().GetProperty(name, Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
        Return DirectCast(info.GetValue(targetClass, Nothing), T)
    End Function
    <System.Runtime.CompilerServices.Extension()>
    Public Function FindByName(Of T)(name As String, targetClass As Object) As T
        Dim info As Reflection.PropertyInfo = targetClass.GetType().GetProperty(name, Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
        Return DirectCast(info.GetValue(targetClass, Nothing), T)
    End Function
End Module

출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=45&MAEULNO=18&no=509&page=1

'프로그래밍 > VB.net' 카테고리의 다른 글

VB.net - 파일의 MD5 Hash 값 추출  (0) 2015.05.11
VB.net - 문자열로 Form 객체 반환 받기  (0) 2015.05.11

+ Recent posts