Hi,

I have a custom Attribute class where the constructor takes one fixed parameter and two optional parameters. It is my understanding that one can supply one or more optional parameters by using 'named parameters' such as this:
Code:
Private Sub CallMethod()
   Me.OptionalMethod(-1, z:=1)
End Sub

Private Sub OptionalMethod(ByVal x As Integer, Optional ByVal y As Integer = 0, Optional ByVal z As Integer = 10)
   '...
End Sub
This way I skip the 'y' parameter and simply let it use the default value of 0. This works fine for any class, except apparently for attributes...

This is my attribute class:
vb.net Code:
  1. <AttributeUsage(AttributeTargets.Property, AllowMultiple:=False)> _
  2.     Public Class GridOptionsAttribute
  3.         Inherits System.Attribute
  4.  
  5.         Public Sub New(ByVal visible As Boolean, Optional ByVal text As String = Nothing, Optional ByVal index As Integer = -1)
  6.             _DisplayName = text
  7.             _Visible = visible
  8.             _DisplayIndex = index
  9.         End Sub
  10.  
  11.         Private _DisplayName As String
  12.         Public ReadOnly Property DisplayName() As String
  13.             Get
  14.                 Return _DisplayName
  15.             End Get
  16.         End Property
  17.  
  18.         Private _Visible As Boolean
  19.         Public ReadOnly Property Visible() As Boolean
  20.             Get
  21.                 Return _Visible
  22.             End Get
  23.         End Property
  24.  
  25.         Private _DisplayIndex As Integer
  26.         Public ReadOnly Property DisplayIndex() As Integer
  27.             Get
  28.                 Return _DisplayIndex
  29.             End Get
  30.         End Property
  31.  
  32.     End Class

When I try to use it, I cannot seem to use named parameters:


Huh?

Well, I thought, perhaps Attributes don't support named parameters. I know they can behave a little weird (they don't support all types in their arguments for example I think), so I thought little of it.

But then... I noticed something else. If you take a look at my code of the attribute class again. Notice that I am using an attribute on that class as well... And what do you know: named parameters. Working just fine... The AttributeUsage attribute has the exact same configuration: one fixed parameter and two optional parameters. I seem to be able to call them using named parameters just fine, where I cannot call my own attribute constructor with named parameters...

What's going on... Am I losing my mind? Is VS bugged? Or is it infected with a demon?