All rules
CA2263Usage Enabled by default: As suggestion
Prefer generic overload when type is known
Prefer generic overload when type is known
Microsoft docsDescription
Generic overloads are preferable to overloads that accept an argument of type System.Type when the type is known at compile time (using the typeof operator in C# or the GetType operator in Visual Basic). Generic overloads promote cleaner and more type-safe code with improved compile-time checks.
Cause
A method overload that accepts a System.Type argument is called when the type is known at compile time and a suitable generic overload is available.
How to fix violations
To fix a violation of this rule, use the suitable generic overload.
Example
int size = Marshal.SizeOf(typeof(bool));
int size = Marshal.SizeOf<bool>();When to suppress
It is safe to suppress a warning from this rule; however, we recommend that you use a generic overload if possible.
Your vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0