Created
July 5, 2012 15:13
-
-
Save wonderful-panda/3054264 to your computer and use it in GitHub Desktop.
あれば便利な気がするけどわざわざ作るほどでもない気もする拡張メソッドたち
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Module Extensions | |
<Extension()> _ | |
Public Function This(Of T)(ByVal target As T) As T | |
Return target | |
End Function | |
<Extension()> _ | |
Public Function IsNull(Of T As Class)(ByVal target As T) As Boolean | |
Return target Is Nothing | |
End Function | |
<Extension()> _ | |
Public Function IsNotNull(Of T As Class)(ByVal target As T) As Boolean | |
Return target IsNot Nothing | |
End Function | |
<Extension()> _ | |
Public Function Or_(Of T As Class)(ByVal target As T, ByVal Func(Of T) factory) As T | |
If target Is Nothing Then | |
Return factory() | |
Else | |
Return target | |
End If | |
End Function | |
<Extension()> _ | |
Public Function IsOneOf(Of T)(ByVal target As T, ParamArray candidates() As T) As Boolean | |
Return candidates.Contains(target) | |
End Function | |
End Module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'' 使いみち | |
'' This/IsNull/IsNotNull は Withと一緒に | |
With GetFooInstance() | |
If .IsNull Then | |
Return False | |
End If | |
.DoSomething() | |
list.Add(.This) | |
End With | |
'' IsOneOf は If文で | |
If a.IsOneOf(1, 2, 3) Then '' If a = 1 OrElse a = 2 OrElse a = 3 Then の代わりに | |
... | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment