jpb*_*chi 5 .net c# reflection custom-attributes
我正在寻找在参数中放置属性的合理用例列表.
我可以想一下方法中属性的一些好例子,但似乎看不到参数属性的良好用法.拜托,赐教.
那么方法的返回类型的属性呢?
使用它们的具体情况是在PInvoke中.PInvoke签名中的参数可以通过使用属性可选地使用其他信息进行修饰,以便可以显式指定PInvoke单个参数的编组或者覆盖默认的编组行为,例如:
[DllImport("yay.dll")]
public static extern int Bling([MarshalAs(UnmanagedType.LPStr)] string woo);
Run Code Online (Sandbox Code Playgroud)
这将覆盖字符串参数"woo"的默认编组行为.