Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As pointed by <a href="https://stackoverflow.com/users/60188/anton-gogolev">Anton Gogolev</a>, attributes can be created using PostSharp.(note that CodeContract is using static method calls inside body of method)</p> <p>UPDATE Feb 2013: new 3.0 release of PostSharp (currently in Beta) will support <a href="http://www.sharpcrafters.com/blog/post/Validating-parameters-field-and-properties-in-PostSharp-3.aspx" rel="nofollow noreferrer">Validating parameters, fields and properties</a></p> <p>1) Article <a href="http://dpatrickcaldwell.blogspot.com.au/2009/03/validate-parameters-using-attributes.html" rel="nofollow noreferrer">validate-parameters-using-attributes</a> has implementation of</p> <blockquote> <p>public class NotEmpty : ParameterAttribute</p> <p>public class NotNull : ParameterAttribute</p> <p>[AttributeUsage(AttributeTargets.Parameter)] </p> <p>public abstract class ParameterAttribute : Attribute </p> <p>{</p> <pre><code>public abstract void CheckParameter(ParameterInfo parameter, object value); </code></pre> <p>}</p> </blockquote> <p>It also Required a method attribute with a method boundary aspect to process the parameter attributes.</p> <p>2) In the comment to the article there are links to <a href="http://code.google.com/p/postsharp-user-plugins/wiki/DesignByContract" rel="nofollow noreferrer">very similar implementation</a> for NonNull/NonEmpty    </p> <blockquote> <p>[return: NonNull] public SomeObject SomeMethod([NonNull] AnotherObject param1)      </p> </blockquote> <p>The source code is located In <a href="http://postsharp-user-plugins.googlecode.com/svn/trunk/1.5/Torch/DesignByContract.Weaver/" rel="nofollow noreferrer">google code Torch/DesignByContract</a></p> <p>3) another more complicate example is described in <a href="http://badecho.com/2011/11/validating-method-parameters-with-postsharp/" rel="nofollow noreferrer">http://badecho.com/2011/11/validating-method-parameters-with-postsharp/</a>       </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload