I want to let programmers and myself know that a method does not want null and if you do send null to it anyways, the result will not be pretty. >
As pointed by Anton Gogolev, attributes can be created using PostSharp.(note that CodeContract is using static method calls inside body of method)
UPDATE Feb 2013: new 3.0 release of PostSharp (currently in Beta) will support Validating parameters, fields and properties
1) Article validate-parameters-using-attributes has implementation of
public class NotEmpty : ParameterAttribute
public class NotNull : ParameterAttribute
[AttributeUsage(AttributeTargets.Parameter)]
public abstract class ParameterAttribute : Attribute
{
public abstract void CheckParameter(ParameterInfo parameter, object value);}
It also Required a method attribute with a method boundary aspect to process the parameter attributes.
2) In the comment to the article there are links to very similar implementation for NonNull/NonEmpty
[return: NonNull] public SomeObject SomeMethod([NonNull] AnotherObject param1)
The source code is located In google code Torch/DesignByContract
3) another more complicate example is described in http://badecho.com/2011/11/validating-method-parameters-with-postsharp/