-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.BadPractice.DoNotUseGetInterfaceToCheckAssignabilityRule(2.10)
Sebastien Pouliot edited this page Jan 22, 2011
·
2 revisions
Assembly: Gendarme.Rules.BadPractice
Version: 2.10
This rule checks for calls to Type.GetInterface that look like they query if a type is supported, i.e. the result is only used to compare against null. The problem is that only assembly qualified names uniquely identify a type so if you just use the interface name or even just the name and namespace you may get unexpected results.
Bad example:
if (type.GetInterface ("IConvertible") != null) {
// then the type can be assigned to IConvertible
// but what if there is another IConvertible in there ?!?
}
Good example:
if (typeof (IConvertible).IsAssignableFrom (type)) {
// then the type can be assigned to IConvertible
// without a doubt!
}
- This rule is available since Gendarme 2.2
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!