1

I was going through the source code for StreamReader where I found -

public override int Read([In, Out] char[] buffer, int index, int count)
{

}

Can some one please shed some light on what the [In , Out] thing of the first parameter means?

Amit Kumar Ghosh
  • 3,618
  • 1
  • 20
  • 24

1 Answers1

3

They are attributes (parameter attributes) having [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]

The target of an attribute is the entity to which the attribute applies. For example, an attribute may apply to a class, a particular method, or an entire assembly. By default, an attribute applies to the element that it precedes. But you can also explicitly identify, for example, whether an attribute is applied to a method, or to its parameter, or to its return value.

-referenced from here

InAttribute and OutAttribute has been defined like this:

[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()
    {
    }
}

Look at here on referencesource.microsoft.com for more detail on those attribute classes.

Jenish Rabadiya
  • 6,708
  • 6
  • 33
  • 62
  • [Here](https://msdn.microsoft.com/en-us/library/z0w1kczw.aspx) is article from msdn as well for detail study of the same. – Jenish Rabadiya Dec 03 '15 at 06:14
  • 2
    You should add that article to your answer and probably provide some of those details, in case those links fail to work at a later date, as they sometimes do. – B.K. Dec 03 '15 at 06:16