[Mono-list] mBas

Marco Ridoni marco.ridoni@virgilio.it
Mon, 27 Jan 2003 20:11:09 +0100


I have added support for attributes to mBas (beside other fixes).  The
following code compiles and runs fine. The area which needs more attention
is array declaration and access, as you can see yourself from the apparently
weird access method used to retrieve an Annotation object - calls like
'MyAnnotation = tc_type.GetCustomAttributes(False)(0)' wouldn't work mainly
because the grammar still fails to recognize them. I'm currently working on
this.

Marco Ridoni
marco.ridoni@virgilio.it

P.S. I just realized I forgot to remove some code which generates debug
output while compiling. I wil take care of it ASAP

=========================

Imports System
Imports System.Reflection


<AttributeUsage(AttributeTargets.All, Inherited:=True, AllowMultiple:=True)>
_
Public Class Annotation
    Inherits System.Attribute

    Protected strAuthor As String
    Protected strComment As String

    Public Sub New(ByVal Author As String, ByVal Comment As String)
        strAuthor = Author
        strComment = Comment
    End Sub

    Public Property Author() As String
        Get
            Author = strAuthor
        End Get

        Set(Value As String)
            strAuthor = CStr(Value)
        End Set
    End Property

    Public Property Comment() As String
        Get
            Return strComment
        End Get
        Set(Value As String)
            strComment = CStr(Value)
        End Set
    End Property

End Class

<Annotation("mr", "This is a test")> _
Public Class TestClass

 Public Sub New(a As integer,b As integer,c As integer)

 End Sub

 Public Sub SayWhoYouAre()

 End Sub
End Class

Module Test


Dim tc As TestClass

Public Sub Main()
 Dim tc_type As Type
 Dim MyAnnotation As Annotation
 Dim obj(2) As Object

 tc = New TestClass(2,3,4)
 tc_type = tc.GetType()
 obj = tc_type.GetCustomAttributes(False)
 MyAnnotation = CType (obj(0), Annotation)

 Console.WriteLine("Author is '" & MyAnnotation.Author & "'")
 Console.WriteLine("Comment is '" & MyAnnotation.Comment & "'")
End Sub

End Module