[Mono-devel-list] Re: [mono-vb] VB Class status

A Rafael D Teixeira rafaelteixeirabr at hotmail.com
Wed Jun 23 15:43:54 EDT 2004


>From: "Jambunathan Jambunathan" <kjambunathan at novell.com>
>The errors in Microsoft.VisualBasic may seem intimidating at first.
>Most of the errors are due to a mismatch in the Parameter Attributes.
>Many VB functions/methods support optional parameters with a default
>value. MS's dll marks the Parameter with Optional, HasDefault
>In our C# implementation of the method, we mark such parameters using
>following two attributes: System.Runtime.InteropServices.Optional
>and System.ComponentModel.DefaultValue(). As a result Mono's dll has
>Parameter Attributes just set to Optional ( but has no HasDeafult ).
>I am not sure whether this is bug or a baggage not carried from the
>( Quick googling suggested that just using C# it's not possible to
>create a parameter with Parameter Attributes set to Optional |
>Just posting to the mailing list with the hope that I will get a quick

It's indead trickier:

code like

   Private Sub x(ByVal w As String, Optional ByVal y As Integer = 132)
        TextBox1.Text = w & y
    End Sub

    Private Sub z()
        x("what", 1)
    End Sub

generates things like

.method private instance void  x(string w,
                                 [opt] int32 y) cil managed
  .param [2] = int32(0x00000084)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldarg.0
  IL_001a:  ret
} // end of method Form1::x

we need to generate it properly for MS.VB.Dll but we still need more 
information to know how. What makes that .param [n] appear there? [opt] 
comes from the Optional attribute? it seems so, but ...

That is why I guessed DefaultValue, but it seems it is not the proper thing 
to use...

Maybe our truly Jackson of mono´s ilasm fame can bear some light for us...


.method private instance void  z() cil managed
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldarg.0
  IL_0002:  ldstr      "what"
  IL_0007:  ldc.i4.1
  IL_0008:  callvirt   instance void TesteXmlNText.Form1::x(string,
  IL_000d:  nop
  IL_000e:  ldarg.0
  IL_000f:  ldstr      "whatnot"
  IL_0014:  ldc.i4     0x84
  IL_0019:  callvirt   instance void TesteXmlNText.Form1::x(string,
  IL_001e:  nop
  IL_001f:  nop
  IL_0020:  ret
} // end of method Form1::z

that mbas must take care to generate, see that the compiler discover the 
default value and pass it
to the method, but it complicates even more when you add overload-resolution 
to the figure, and also late-binding (we will have to implement all that 
policies inside the helping classes in MS.VB.dll also).

So indeed a long way to go,

Have fun boys,

Rafael "Monoman" Teixeira
Mono Hacker since 16 Jul 2001 - http://www.go-mono.org/
MonoBrasil Founding Member - Membro Fundador do MonoBrasil 
English Blog: http://monoblog.blogspot.com/
Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/

MSN Messenger: instale grátis e converse com seus amigos. 

More information about the Mono-devel-list mailing list