3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

拡張メソッド(VB.Net)

Last updated at Posted at 2015-06-10

VB.NETでの拡張メソッドの書き方のメモ

System.Runtime.CompilerServices を インポートします。
Module で作成します。

また後で追記します。

Extensions.vb
Imports System.Runtime.CompilerServices

Public Module HogeExtensions

    <Extension>
    Public Function IsNullOrEmpty(Byval value As String) As Boolean

        Return String.IsNullOrEmpty(value)

    End Function

    '' VB.Net を使用すると メール送信にSmtpClientを使用することが多いと思います。
    '' そのため、メールアドレスのチェックはMailAddressクラスで
    '' チェックすることをお勧めします。
    <Extension>
    Public Function IsMailAddress(Byval value As String) As Boolean

        If value.IsNullOrEmpty Then
            Return False
        Else
            Try
                Dim MailAddress As New System.Net.Mail.MailAddress(value)
                Return True
            Catch ex As FormatException
                Return False
            End Try
        End If
    End Function

End Module

使用方法

Main.vb
Sub Main

    If "hoge@example.com".IsMailAddress Then
        ' Trueの処理
    Else
        ' Falseの処理
    True

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?