C#: How to Implement and use a NotNull and CanBeNull attribute -
I programmers want to do and you know that is not a method is a But how does this work? I looked at the source code of those two characteristics, and it looks like this: null anyway, the result will not be very good is NotNullAttribute and a in CanBeNullAttribute , in Lokad.Quality namespace
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets. Field, AllowMultiple = false, Inherited = true)] [NoCodeCoverage] public sealed class NotNullAttribute: properties {} [AttributeUsage (AttributeTargets.Method from | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field, AllowMultiple = false, traditionally obtained = true)] [NoCodeCoverage] public sealed class CanBeNullAttribute: properties {} properties from inheriting two empty room S. How are they used? Do you have to see the XML documentation and know that it is there? Because I tried to copy both their attributes and use the local version, but when I tried to send a blank in direct, I could not find any message. Neither Rasarar nor V.S. To In fact like what I really expected But how are they used? Can I somehow make warnings for VS to me if I try to send something that is empty there? Or is it just used in some kind of test framework? Or?
In the middle period, the "code contract" (in 4.0) will be a better answer for it. They are now available (or with license), but they will become more integrated in VS-2010. It can provide both static analysis and runtime support.
(Edit) Example:
Agreement. Request always (x! = Null); It's that simple ... code contract works on engine IL level, so it threw to call code in a can analyze it and build or warning / errors Could. For backward compatibility, if you have an existing verification code, then you are finished examining the conscience where you can tell it only, and it will do the rest:
if (x == null ) Remove the new logic ("X"); Contract.EndContractBlock ();
Comments
Post a Comment