【发布时间】:2015-12-03 06:09:11
【问题描述】:
我正在浏览我找到的StreamReader 的源代码 -
public override int Read([In, Out] char[] buffer, int index, int count)
{
}
有人能解释一下第一个参数的[In , Out] 是什么意思吗?
【问题讨论】:
标签: c# streamreader
我正在浏览我找到的StreamReader 的源代码 -
public override int Read([In, Out] char[] buffer, int index, int count)
{
}
有人能解释一下第一个参数的[In , Out] 是什么意思吗?
【问题讨论】:
标签: c# streamreader
它们是具有[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]的属性(参数属性)
属性的目标是属性应用到的实体。例如,属性可以应用于类、特定方法或整个程序集。默认情况下,属性应用于它之前的元素。但您也可以显式识别,例如,属性是应用于方法,还是应用于其参数,或应用于其返回值。
-引用自here
InAttribute 和 OutAttribute 的定义如下:
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class InAttribute : Attribute
{
internal static Attribute GetCustomAttribute(RuntimeParameterInfo parameter)
{
return parameter.IsIn ? new InAttribute() : null;
}
internal static bool IsDefined(RuntimeParameterInfo parameter)
{
return parameter.IsIn;
}
public InAttribute()
{
}
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class OutAttribute : Attribute
{
internal static Attribute GetCustomAttribute(RuntimeParameterInfo parameter)
{
return parameter.IsOut ? new OutAttribute() : null;
}
internal static bool IsDefined(RuntimeParameterInfo parameter)
{
return parameter.IsOut;
}
public OutAttribute()
{
}
}
查看referencesource.microsoft.com 上的here,了解有关这些属性类的更多详细信息。
【讨论】: