NativeMethods class should be static and internal
As explained in Move P/Invokes to NativeMethods class, NativeMethods classes hosting P/Invoke methods should be static and internal. Warns about those that are not.
How to fix
Declare matched NativeMethods classes static and internal.
CQLinq source
This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.
// <Name>NativeMethods class should be static and internal</Name>
// <Id>ND2402:NativeMethodsClassShouldBeStaticAndInternal</Id>
warnif count > 0 from t in Application.Types.WithNameIn(
@"NativeMethods", "SafeNativeMethods", "UnsafeNativeMethods") where
t.IsPublic || !t.IsStatic
select new {
t,
t.Visibility,
t.IsStatic,
Debt = 5.ToMinutes().ToDebt(),
Severity = Severity.Medium
}
//<Expl>
// The *{0}* should only contain *P/Invoke methods*,
// so it should be declared as both *static* and *internal*.
//</Expl>
//<Desc>
// As explained in *Move P/Invokes to NativeMethods class*, *NativeMethods*
// classes hosting *P/Invoke* methods should be *static* and *internal*.
// Warns about those that are not.
//</Desc>
//<HowToFix>
// Declare matched *NativeMethods* classes *static* and *internal*.
//</HowToFix>
Open in the interactive Rules Explorer · All default rules
.NET Framework Usage / System.Runtime.InteropServices: all 3 items
- P/Invokes should be static and not be publicly visible ND2400
- Move P/Invokes to NativeMethods class ND2401
- NativeMethods class should be static and internal ND2402