投稿数 - 437, コメント - 55134, トラックバック - 156

CA1002

public List<Hoge> GetHogeList()
{
    return new List<Hoge>();
}

コード分析的にはこのコードは駄目らしい。「CA1002 ジェネリック リストを公開しません」だ。原文は「Do not expose generic lists 」なので、「ジェネリックリストを公開するな(公開しないでください)」がスッキリな訳だと思うが。

List<T> をパブリックに使うのは駄目で、あくまでプライベートに使いなさいという事かな。だったら ArrayList で十分だ。プライベートに使っている間は ArrayList に何が入っているのか完全に把握しているから、「厳密に型指定できるんだよ!」というのは List<T> を使用する動機としては弱い。

「パフォーマンスが違うんだよ!」というのも何か弱い。それでも ArrayList よりは List<T> のほうがマシと言えばマシだが。

いちいちコレクションクラスを作る面倒が大幅に削減できると思ったのだが、勘違いか?

public class HogeCollection : List<Hoge> { };

List<T> の唯一の有効な使い方はこれしかない?確かにコレクションクラスを作るのが非常に楽になった。

投稿日時 : 2006年9月22日 19:21

フィードバック

# re: CA1002

はじめまして。こっそり色々参考にさせていただいてます。

コード分析は使ったこと無いので見当違いかもしれませんが、戻り値の型を IList<T> にすればいいって話では無いんですかね?
List<T>だと実装を公開してることになるので、インターフェースだけ公開するようにしろ、みたいな。
2006/09/22 20:29 | aki.

# re: CA1002

「genegricsが使えない.NET族もいるから遠慮しろ」なんてー消極的な理由だったり ^^;
2006/09/22 20:44 | επιστημη

# re: CA1002

>コード分析は使ったこと無いので見当違いかもしれませんが、戻り値の型を IList<T> にすればいいって話では無いんですかね?
>List<T>だと実装を公開してることになるので、インターフェースだけ公開するようにしろ、みたいな。

お~、その発想はなかったですね。試しにやってみた所、OKが出ました!
何か釈然としませんが、言われてみると納得です。ありがとうございます。

>「genegricsが使えない.NET族もいるから遠慮しろ」なんてー消極的な理由だったり ^^;

この理由もありそうですね。あれ?って事はジェネリクスを使うと CLS 準拠じゃなくなる?


しかし、MSDN の日本語訳は分かりにくいなぁ。
「外部から参照可能な System.Collections.Generic.List 型のメンバを含む型が System.Collections.Generic.List 型を返すか、その署名に System.Collections.Generic.List パラメータが含まれています。」
「署名」ってなんだ?と思ったら「シグネチャ」の事でした。
2006/09/22 21:54 | 囚人

# [.NET] CA1002

なんか誰も書いてないみたい ( というか、 ぐぐる様に引っかからない ) なので、 メモ。 囚人のジレンマな日々 の CA1002 で、 コード分析 ( FxC

# re: CA1002

古い記事にトラックバック掛けて恐縮です。
ぐぐる様に聞いたら、 ここがトップだったもので… f(^^;
http://www.google.co.jp/search?hl=ja&q=CA1002+System.Collections.Generic.List&lr=lang_ja
2008/02/25 20:01 | biac

# If you are going for most excellent contents like I do, simply pay a quick visit this web site daily since it gives feature contents, thanks

If you are going for most excellent contents like I do, simply pay a quick visit this web
site daily since it gives feature contents, thanks

# It's great that you are getting thoughts from this article as well as from our dialogue made here.

It's great that you are getting thoughts from
this article as well as from our dialogue made here.

# Hello, I enjoy reading through your post. I like to write a little comment to support you.

Hello, I enjoy reading through your post. I like to write a
little comment to support you.

# Hi there! I realize this is kind of off-topic however I had to ask. Does managing a well-established website like yours require a massive amount work? I'm completely new to writing a blog but I do write in my journal everyday. I'd like to start a blog s

Hi there! I realize this is kind of off-topic however I had to
ask. Does managing a well-established website
like yours require a massive amount work?
I'm completely new to writing a blog but I do write in my journal everyday.
I'd like to start a blog so I can easily share my experience and views online.
Please let me know if you have any kind of recommendations or tips for new aspiring bloggers.

Appreciate it!

# We are a gaggle of volunteers and starting a brand new scheme in our community. Your website offered us with valuable information to work on. You've performed an impressive job and our entire neighborhood might be grateful to you.

We are a gaggle of volunteers and starting a brand new scheme in our community.

Your website offered us with valuable information to work on. You've performed
an impressive job and our entire neighborhood might be grateful to you.

# We are a gaggle of volunteers and starting a brand new scheme in our community. Your website offered us with valuable information to work on. You've performed an impressive job and our entire neighborhood might be grateful to you.

We are a gaggle of volunteers and starting a brand new scheme in our community.

Your website offered us with valuable information to work on. You've performed
an impressive job and our entire neighborhood might be grateful to you.

# We are a gaggle of volunteers and starting a brand new scheme in our community. Your website offered us with valuable information to work on. You've performed an impressive job and our entire neighborhood might be grateful to you.

We are a gaggle of volunteers and starting a brand new scheme in our community.

Your website offered us with valuable information to work on. You've performed
an impressive job and our entire neighborhood might be grateful to you.

# We are a gaggle of volunteers and starting a brand new scheme in our community. Your website offered us with valuable information to work on. You've performed an impressive job and our entire neighborhood might be grateful to you.

We are a gaggle of volunteers and starting a brand new scheme in our community.

Your website offered us with valuable information to work on. You've performed
an impressive job and our entire neighborhood might be grateful to you.

# prednisone canada

can you buy prednisone over the counter in canada https://prednisonebestprice.pro/# iv prednisone
prednisone tablets
2024/08/06 17:09 | Stevenput

# furosemida 40 mg

buy cytotec over the counter http://tamoxifen.bid/# tamoxifen cyp2d6
lasix 100mg
2024/08/19 19:17 | DanielEruts

# lasix tablet

buy cytotec in usa https://tamoxifen.bid/# tamoxifen and weight loss
furosemide 40 mg
2024/08/20 15:04 | DanielEruts

# lasix generic name

cytotec online http://tamoxifen.bid/# tamoxifen headache
lasix uses
2024/08/23 0:31 | DanielEruts

# lasix furosemide

cytotec abortion pill https://tamoxifen.bid/# tamoxifen dose
buy furosemide online
2024/08/24 2:30 | DanielEruts

# mexican border pharmacies shipping to usa

https://mexstarpharma.com/# pharmacies in mexico that ship to usa
2024/08/27 18:52 | Jeremymet

# vavada казино

https://vavada.auction/# вавада рабочее зеркало
2024/09/05 16:20 | Warrenpseut

# gates of olympus demo

http://betine.online/# betine giris
2024/09/19 21:07 | GeorgeMum

# gates of olympus turkce

http://starzbet.shop/# starzbet giris
2024/09/20 12:58 | GeorgeMum

# gates of olympus giris

https://gatesofolympusoyna.online/# gates of olympus giris
2024/09/21 5:45 | GeorgeMum

# farmacias online seguras en espaГ±a

https://farmaciaeu.com/# farmacias direct
п»?farmacia online espaГ±a
2024/09/21 21:16 | FloydUnorm

# se puede comprar sildenafil sin receta

http://farmaciaeu.com/# farmacia online madrid
2024/09/22 6:47 | DennisevElp

# sildenafilo 100mg precio espaГ±a

http://tadalafilo.bid/# farmacia online barata y fiable
2024/09/23 2:58 | DennisevElp

# farmacias online baratas

http://farmaciaeu.com/# farmacias online seguras
farmacia online barata y fiable
2024/09/23 4:31 | FloydUnorm

# Farmacia online miglior prezzo

https://tadalafilit.com/# farmacie online affidabili
farmacia online
2024/09/23 20:16 | Charlesnub

# can i buy ventolin over the counter in canada

http://gabapentin.site/# gabapentin 100mg
2024/09/28 4:09 | Sergiodab

# ventolin 2.5 mg

https://prednisolone.pro/# where to buy prednisone in australia
2024/09/29 12:48 | Sergiodab

# Achat mГ©dicament en ligne fiable

https://pharmaciepascher.pro/# pharmacie en ligne
2024/10/03 21:40 | StephenWadly

# pharmacie en ligne france fiable

https://clssansordonnance.icu/# vente de mГ©dicament en ligne
2024/10/04 10:18 | StephenWadly

コメントの投稿

タイトル  
名前  
URL
コメント