すいません、VB4しかやってないんです、VBAはやったけど(ぼそ) チラシの裏だって立派な書き込み空間なんだからねっ!資源の有効活用なんだからねっ!とか偉そうに言ってるけど、実は色々と書き残したいだけ

だからなに? どうしろと? くるみサイズの脳みそしかないあやしいジャンガリアンベムスターがさすらう贖罪蹂躙(ゴシックペナルティ)

ホーム 連絡をする 同期する ( RSS 2.0 ) Login
投稿数  632  : 記事  35  : コメント  11675  : トラックバック  143

ニュース


片桐 継 は
こんなやつ

かたぎり つぐ ってよむの

大阪生まれ河内育ちなんだけど
関東に住みついちゃったの
和装着付師だったりするの
エセモノカキやってたりするの
VBが得意だったりするの
SQL文が大好きだったりするの
囲碁修行中だったりするの
ボトゲ好きだったりするの
F#かわいいよF#

正体は会った人だけ知ってるの

空気読まなくてごめんなさいなの


わんくまリンク

C#, VB.NET 掲示板
C# VB.NET掲示板

わんくま同盟
わんくま同盟Blog


WindowsでGo言語
WindowsでGo言語


ネット活動


SNSは疲れました

記事カテゴリ

書庫

日記カテゴリ

ギャラリ

イベント活動

プログラムの活動

むかし、派手に使いまくってたっていうぜ?

処理するうえで、とっても困っていた事。

えくすてんしょん、で、えくすくらめーしょん
http://blogs.wankuma.com/esten/archive/2010/04/25/188400.aspx

を使っていたのはよいのだけれど、ふと、気付いた。

DBNullとNothingは異なる、ってこと。

今回のケース、DataTableからLINQしてList(of 別のクラス)を生成し、
また、List(of 別のクラス)の中身をDataTableと同期させたり
とかしてるんだけど、

DBNullとなっている列のデータは、Nothingにしておかないとクラス内では都合が悪い

Nothingのクラスプロパティは、DBNullになってくれないと、DataTable内では都合が悪い

というわけで、コンバータが必要になっちゃったのね。

でも、関数だといちいち書くのめんどいから、

どうせならObject型の拡張メソッドにしちゃえ、ということで頑張ってみた。

image

まずは「クラスライブラリプロジェクト」を作成。

そこにクラスを追加して、Object型への拡張なので、それらしい名前をつけておく。

Imports System.Runtime.CompilerServices

Public Module ObjectExtentions

    <Extension()> _
    Public Function NVL(ByVal invalue As Object) As Object

        Select Case True
            Case IsDBNull(invalue)
                Return Nothing
            Case invalue Is Nothing
                Return DBNull.Value
            Case Else
                Return invalue
        End Select

    End Function

End Module

メソッド名は、自分が使いなれている(!)NVL、と名付けてコンバータを作成。簡単なロジックw

ちなみに、パラメータにObjectを指定すると、
CompilerServicesの方で、「あ、これObject型用の拡張なのね」と判断してくれる

そして、プロジェクト生成のところで、ルート名前空間に「System」を指定

image

はい、リビルドー!オブジェクトブラウザで、できているのを確認!

image

そして、これを、使いたい処理プロジェクトで参照追加しておくと、

image

インテリセンスでも存在確認!

image

サンプルの是非はおいといて(テケトーだから)、オブジェクト型に拡張したから、何にでも付けられちゃうゾw

というわけで、これで、どんな型でも必要に応じてコンバーター処理できるようになりましたですよ。

拡張メソッド (Visual Basic)
http://msdn.microsoft.com/ja-jp/library/bb384936.aspx

くわしくは、こちらにね。

投稿日時 : 2010年5月13日 14:07

コメント

# re: NVLって知ってるかい? 2010/05/13 17:38 aetos
名前空間 System は行儀悪いんじゃないかなぁ…
俺は coalesce をよく使います。.NET 的に名前を選ぶなら ISNULL がいいかも。

そして、「Select Case True」にはのけぞったww

# re: NVLって知ってるかい? 2010/05/13 17:39 aetos
ちなみにそいつは Nothing.NVL() でも動くという気持ち悪さ。

# re: NVLって知ってるかい? 2010/05/13 18:45 かたぎり
ひゃっほー、あえとすちゃんだー

結局、System.ObjectExtentions という名前で使いかたかったからそうしたの。
System.Object の Extension だもの。

SelectCase True ってVBだから書けるSelect文で
愛用してまするw

isNulll かぁ。
なんか返り値がBooleanっぽいなぁ、とおもって
isXXX系とかは変換処理には使わない名前だったりするん

Nothing.NVL って、あ、それ、おもしろいwww

でも書くことないし<おい



# re: NVLって知ってるかい? 2010/05/14 12:19 noname
つ http://msdn.microsoft.com/ja-jp/library/ms184325.aspx

# re: NVLって知ってるかい? 2010/05/14 12:28 かたぎり
>ななしさん?

あ、そっちのisnullかぁ!
付けようとしてる関数の名前の話だと思ってた

そうね、列名を細かく指定してSELECTしてるのだったら
T-SQLでISNULLかます方が皆の幸せになるわよね

今回、諸事情によりSELECT * で共通orz
だから苦しんでるわけだけど。

# re: NVLって知ってるかい? 2010/05/14 16:50 aetos
System は行儀悪いという以外にお勧めしない理由をもう一つ思いついた。
それは、System.ObjectExtensions クラスは2つ存在できないということ。
何らかの事情により似たようなクラスをもう一つ作る、あるいは他人(MS含む)が作ったライブラリに含まれている場合、名前がバッティングする。
それを避けるための名前空間なのに、System にすることで、名前空間の意義が半ば失われる。
ユニークな名前にしておけばこの問題は起きない。

IsNull が Boolean ぽくて向かないのはおっしゃる通り。
このへんにも使われていたりする http://msdn.microsoft.com/ja-jp/library/system.data.datacolumn.expression.aspx

# re: NVLって知ってるかい? 2010/05/14 17:49 かたぎり
>あえとすちゃん

そうだね、新しくクラス作ったり
参照を増やす時には気をつけなくちゃになるね


# re: NVLって知ってるかい? 2013/03/18 12:49 ljadsa
no me gusto lo que pusiste

# re: Ruby で数値を 0 埋めする 2019/01/24 13:44 zzyytt
http://www.goyard.us.com
http://www.stephencurry.us.com


# re: Ruby で数値を 0 埋めする 2019/01/24 14:16 zzyytt
http://www.vapormaxshoes.us
http://www.yeezy-boost350.us.com
http://www.ultraboost.us.com
http://www.adidasstansmith.us.com
http://www.yeezy-500.us.com
http://www.michaelkors-outletonlines.us.com
http://www.lebron16.net
http://www.goyard.us.com
http://www.stephencurry.us.com
http://www.toryburchs.us
http://www.russellwestbrookshoes.us
http://www.lebron16.us.com
http://www.supremeclothing.us
http://www.adidasyeezys.us.com
http://www.golden-goose.us.com
http://www.redbottom-shoes.us.com
http://www.kobebasketballshoes.net
http://www.bapehoodie.us
http://www.outletonline-michaelkors.us.org
http://www.yeezyboost.com.co


# nfl jerseys 2019/04/12 2:50 jbgpqrjeu@hotmaill.com
krrmjtwvq,Thanks a lot for providing us with this recipe of Cranberry Brisket. I've been wanting to make this for a long time but I couldn't find the right recipe. Thanks to your help here, I can now make this dish easily.

# NBA Jerseys 2019/04/28 4:16 aavjdkej@hotmaill.com
Raja appeared in prison overalls, his head bowed and his hands clasped during testimony from both his relatives and the victim's. His lip trembled with emotion as his wife described how he had sent three letters a day from prison, one each for her and their two children.

# Vapor Max 2019/05/07 2:55 dzhlucxvqrx@hotmaill.com
With several players either pursuing pro opportunities or moving on from UVA, it would be difficult, if not impossible to get everyone back together, Bennett said. We would have to respectfully decline an invitation.

# Pandora Rings 2019/05/11 3:27 qachoe@hotmaill.com
so it is entirely possible for the Fed to quickly reverse the dovish position held since the beginning of 2019. O'Neill said any signs that the Fed is tightening monetary policy will disrupt the US stock market and bond market.

# pandora charms outlet 2019/05/11 10:46 mvtuultl@hotmaill.com
The Jets reportedly had interest in trading down, but stayed at No. 3, and had arguably the best player in the entire draft fall into their laps. Quinnen Williams will be a plug-and-play staple on their defensive line, and he sure looks like a perennial All-Pro. Sometimes the best move is the one you don't make.

# Jordan 12 Gym Red 2018 2019/05/21 0:45 znwvkjpombf@hotmaill.com
http://www.basketball-jersey.us/ Basketball Jersey

# NFL Jerseys 2019/05/24 20:47 exnkrocrsrt@hotmaill.com
http://www.jordan12gymred.us.com/ Air Jordan 12 Gym Red

# Cowboys Jerseys 2019/06/01 19:29 zuewzq@hotmaill.com
http://www.nikefactoryoutletstoreonline.com/ Nike Outlet store

# Travis Scott Jordan 1 2019/06/01 23:44 ftesnxt@hotmaill.com
The Jets reportedly had interest in trading down,Jordan but stayed at No. 3,Jordan and had arguably the best player in the entire draft fall into their laps. Quinnen Williams will be a plug-and-play staple on their defensive line,Jordan and he sure looks like a perennial All-Pro. Sometimes the best move is the one you don't make.

# Nike Air Max 2019 2019/06/04 21:35 avlbvxsmij@hotmaill.com
http://www.customnfljerseys.us/ nfl jerseys

# Nike Outlet 2019/06/19 21:39 jftxujjxch@hotmaill.com
http://www.yeezy350.org.uk/ Yeezy

# Yeezy 2019/06/23 2:02 gpougmyoea@hotmaill.com
http://www.customnfljerseys.us/ cheap custom nfl jerseys

# Yeezy 2019/07/14 8:10 yvobxcpxq@hotmaill.com
http://www.yeezy.com.co/ Yeezy

# Yeezy Shoes 2019/08/01 4:58 utpefg@hotmaill.com
http://www.yeezy350.org.uk/ Yeezy 350

# Nike Outlet Online 2019/08/07 4:32 yaqdawpoim@hotmaill.com
http://www.nikeshoes.us.org/ Nike Shoes

# Yeezy 2019/08/07 5:23 cezfwv@hotmaill.com
http://www.nikeoutletstoreonlineshopping.us/ Nike Outlet

# Yeezy 700 2019/08/13 7:40 yodbwu@hotmaill.com
http://www.yeezy350.org.uk/ Yeezy

# re: NVL????????? 2021/08/07 21:34 hydroxychloroquine
sulfur effects on body https://chloroquineorigin.com/# hydroxychloroquine 200 mg side effects

# zuzbqdgqbcib 2022/05/08 7:53 ukzwyg
what are the side effects of taking hydroxychloroquine? https://keys-chloroquinehydro.com/

# hydroxychloroquine sulfate 2022/12/26 3:47 MorrisReaks
http://hydroxychloroquinex.com/ plaquenil 200 mg cost

Post Feedback

タイトル
名前
Url:
コメント