What is the usefulness of placing attributes on certain method parameters?

I am looking for a list of reasonable use cases for attributes in a parameter.

I can think of some good cases for attributes in a method, but I don't seem to see a good use for the parameter attribute. Please enlighten me.

What about the attributes of the return type of the method?

+5
source share
5 answers

, , PInvoke. PInvoke , Pinnovoke- , , :

[DllImport("yay.dll")]
public static extern int Bling([MarshalAs(UnmanagedType.LPStr)] string woo);   

"woo".

+7

, Vici MVC, .NET MVC, "" . Vici MVC:

public void ActionMethod([Parameter("user")] int userId)
{

}

"" userId.

, .

+3

, , , .

, , , .

+1

Boo -. :

def Foo([required]p):
    pass

Foo :

def Foo(p):
    raise ArgumentNullException("p") if p is null

, .

+1

, , . , MEF , , :

public class Foo {
  [ImportingConstructor]
  public Foo([Import("main")] Bar bar) {
    ...
  }
}
0

All Articles