Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:58:42+00:00 2026-06-07T10:58:42+00:00

CA1004: Generic methods should provide type parameter public static void IfNullAndNullsAreIllegalThenThrow<T>(object value) { if

  • 0

CA1004: Generic methods should provide type parameter

public static void IfNullAndNullsAreIllegalThenThrow<T>(object value)
{
    if (value == null && !(default(T) == null))
        throw new ArgumentException("Nulls are not allowed for this object.");
}

I found this method online, which is quite useful to be honest. But, it violates the CA1004 rule. I’m not sure if there is a better way to design the method and not violate the rules.


Sample usage:

public class SomeClass<T>
{
    public void SomeMethod(object obj)
    {
        // Ensure the actual object is not null if it shouldn't be.
        ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(obj);

        // ...
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:58:43+00:00Added an answer on June 7, 2026 at 10:58 am

    This looks like a helper method which is only used internally. Make it internal instead of public and the warning should go away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fnc: template<class T, T constraint> inline void CheckSize(const T& value) {
How can I suppress FxCop warnings for a whole type? namespace ConsoleApplication1 { public
I have the following definitions: template<typename T1, typename T2> class Test2 { public: static
Its said that property should not be Set only (Code analysis rule CA1044 )and
Possible Duplicate: C#: Difference between List<T> and Collection<T> (CA1002, Do not expose generic lists)
I am running static code analysis with FxCop 1.36 and I keep getting warning
I have a static class 'Defaults' which shall hold default matrices that are forwarded
I have interface in service layer with several methods starting with Get and FxCop's
This is a value in a field called DataFields of a table called objects:
I have a method of an object which is something like a factory. You

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.