All pastes #205249 Raw Edit

tousdan

public text v1 · immutable
#205249 ·published 2006-10-16 17:43 UTC
rendered paste body
Public Class Attribut

    Private _etendue As etendu
    Private _nomAttribut As String
    Private _range As range = Nothing ' :-)
    Private _type As String
    Private _bloc As String

    Private Enum etendu
        Priv
        Pub
        Protect
    End Enum
    Private Enum range
        RO
        WO
    End Enum

    Public ReadOnly Property BlocCode() As String
        Get
            Return _bloc
        End Get
    End Property

    Public Sub New(ByVal UML_String As String)
        Dim str As String = UML_String

        Select Case str.Substring(0, 1) 'Etendue de l'attribut
            Case CChar("+")
                _etendue = etendu.Pub
            Case CChar("-")
                _etendue = etendu.Priv
            Case CChar("#")
                _etendue = etendu.Protect
            Case Else
                Throw New System.Exception("Erreur: Etendue de l'attribut invalide")
        End Select

        str = str.Substring(1) 'On enleve l'etendue

        If Not str.Contains(":") Then Throw New System.Exception("Erreur: Type de l'attribut manquant") 'Tout attribut doit avoir un type

        Dim b As String() = Split(str, ":")
        _nomAttribut = b(0) ' 0 = Nom // 1 = Type + Trash{RO/WO}


        If b(1).Contains("{") Then ' {RO/WO}?
            b = Split(b(1), "{")
            b(1) = b(1).TrimEnd(CChar("}"))
            Select Case b(1).ToLower
                Case "readonly"
                    _range = range.RO
                Case "writeonly"
                    _range = range.WO
                Case Else
                    Throw New System.Exception("Erreur: Accesseur de l'attribut invalide")
            End Select
        End If

        _type = b(0)

        CreerBloc() ' L'objet est structuree
    End Sub
    Public Sub CreerBloc()
        Dim e As String

        'Header(Premiere ligne)
        Select Case _etendue
            Case etendu.Pub
                e = "Public "
            Case etendu.Priv
                e = "Private "
            Case etendu.Protect
                e = "Protected "
        End Select

        Select Case _range
            Case range.RO
                e &= "ReadOnly "
            Case range.WO
                e &= "WriteOnly "
        End Select

        _bloc &= e & "Property " & Me._nomAttribut & " As " & _type

        'Get/Set
        Select Case _range
            Case range.RO
                _bloc &= ControlChars.NewLine & "Get" & ControlChars.NewLine & ControlChars.NewLine & "End Get"
            Case range.WO
                _bloc &= ControlChars.NewLine & "Set(ByVal value As " & _type & ")" & ControlChars.NewLine & ControlChars.NewLine & "End Set"
            Case Else
                _bloc &= ControlChars.NewLine & "Get" & ControlChars.NewLine & ControlChars.NewLine & "End Get" & ControlChars.NewLine & "Set(ByVal value As " & _type & ")" & ControlChars.NewLine & ControlChars.NewLine & "End Set"
        End Select

        'Closer
        _bloc &= ControlChars.NewLine & "End Property" & ControlChars.NewLine
    End Sub

End Class