Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

c# - Are there any good workarounds for FxCop warning CA1006?

I am having trouble with FxCop warning CA1006, Microsoft.Design "DoNotNestGenericTypesInMemberSignatures". Specifically, I am designing a ReportCollection<T> class that inherits from ReadOnlyCollection<Report<T>>, and its public constructor takes an IList<Report<T>> as a parameter.

The suggestion for fixing this warning is not very useful:

"To fix a violation of this rule, change the design to remove the nested type argument." There are two ways I can see so far to change the design as suggested:

  1. Make the constructor internal. This doesn't work in my case. The constructor must be public because this collection class needs to be instantiable by code outside the assembly.
  2. Make the constructor take a Report<T>[] instead of an IList<Report<T>>. This is sub-optimal because external code should have the flexibility of using dynamically-sized data structures like List<T> instead of fixed-size arrays.

At this point, I have given up and suppressed this warning. Is there a better solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would take FxCop's warnings as if they were suggestions from an extremely anal-retentive coworker. It's perfectly ok to ignore (suppress) some of the things it suggests.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...