I'm using ReSharper (older version), which used to warn me when I use PropertyInfo.DeclaringType
that it can be null
.
It doesn't make sense to me at first and second glances. Is it really true, or is ReSharper a bit dumb and doesn't notice that it's a PropertyInfo
, not a general MemberInfo
?
The PropertyInfo.DeclaringType
property is inherited from MemberInfo.DeclaringType
and from documentation:
If the
MemberInfo
object is a global member (that is, if it was obtained from theModule.GetMethods
method, which returns global methods on a module), the returnedDeclaringType
will benull
.
So, warning seems fine in that case.
It can be null
if the property is defined in a module. In C# you cannot define such methods and properties without reflection (see PropertyBuilder
). However, if you reference a VB.NET assembly, it can have such members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With