1

I get following warning:

Possible 'null' assignment to an entity marked with 'Value cannot be null' attribute

My code:

if (verifier.GetType().GetInterface(typeof(IAsyncVerifier).FullName, true) == null)
                {
                    continue;
                }

Warning given on typeof(IAsyncVerifier).FullName part. How that can be null? How would you fix it? Or maybe there is better way to figure if object implements specific interface?

katit
  • 17,375
  • 35
  • 128
  • 256
  • possible duplicate of [Test if object implements interface](http://stackoverflow.com/questions/410227/test-if-object-implements-interface) – V4Vendetta Jan 13 '12 at 04:45

1 Answers1

6

Or maybe there is better way to figure if object implements specific interface?

Use is operator for to check if an object's type is derived from a particular interface or class

if (verifier is IAsyncVerifier)

Look at this MSDN article Type.FullName It says that property will return nothing.

... Nothing if the current instance represents a generic type parameter, an array type, pointer type, or byref type based on a type parameter, or a generic type that is not a generic type definition but contains unresolved type parameters.

If you are sure that when you access FullName this will not be null in any case you can disable this warning using //resharper disable comment

Maheep
  • 5,539
  • 3
  • 28
  • 47