[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


Inline

>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
>attributes.
>
>In our C# implementation of the method, we mark such parameters using
>the
>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
>past.
>( Quick googling suggested that just using C# it's not possible to
>create a parameter with Parameter Attributes set to Optional |
>HasDeafult.
>
>Just posting to the mailing list with the hope that I will get a quick
>response.

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)
        x("whatnot")
    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

<comments>
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...
</comments>

and

.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,
                                                            int32)
  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,
                                                            int32)
  IL_001e:  nop
  IL_001f:  nop
  IL_0020:  ret
} // end of method Form1::z

<comments>
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).
</comments>

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 
http://monobrasil.softwarelivre.org
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. 
http://messenger.msn.com.br




More information about the Mono-devel-list mailing list