Click here to Skip to main content
15,893,622 members
Articles / Programming Languages / Visual Basic

ModelStudio

Rate me:
Please Sign up or sign in to vote.
3.20/5 (4 votes)
6 Dec 2008CPOL4 min read 34.3K   385   28  
Class diagram and code generation tool.
Imports System.ComponentModel
Imports System
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.CollectionEditor
Imports System.ComponentModel.Design.Serialization
Imports System.Globalization
Imports System.Collections
Imports System.Text

''' <summary>
''' A collection of CodeDomPropertyObjects
''' </summary>
''' <remarks></remarks>
<Serializable()> _
Public Class CodeDomClassCollection
    Inherits CollectionBase
    Implements ICustomTypeDescriptor

    Private ctlParent As Object

    Sub New()

    End Sub

    Sub New(ByVal ParentItem As ModelStudio.CodeDomNamespace)
        cParent = ParentItem
    End Sub

    <Browsable(False)> _
    Property cParent() As Object
        Get
            Return ctlParent
        End Get
        Set(ByVal value As Object)
            ctlParent = value
        End Set
    End Property

    Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object)
        CType(newValue, CodeDomClass).Parent = cParent
        MyBase.OnSet(index, oldValue, newValue)
    End Sub

    Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object)
        CType(value, CodeDomClass).Parent = cParent
        MyBase.OnInsert(index, value)
    End Sub

    Default ReadOnly Property Item(ByVal Index As Integer) As CodeDomClass
        Get
            Return DirectCast(List(Index), CodeDomClass)
        End Get
    End Property

    ''' <summary>
    ''' Add a new CodeDomProperty Object
    ''' </summary>
    Public Function Add(ByVal value As CodeDomClass) As CodeDomClass
        List.Add(value)
        Return value
    End Function

    ''' <summary>
    ''' Add a new CodeDomProperty Object
    ''' </summary>
    Public Function Add(ByVal Name As String, ByVal Type As ClassType) As Integer
        Dim prop As New CodeDomClass(Name, Type)
        Return List.Add(prop)
    End Function

    Public Function Contains(ByVal value As CodeDomClass) As Boolean
        Return List.Contains(value)
    End Function

    Public Sub Remove(ByVal value As CodeDomClass)
        List.Remove(value)
    End Sub

    Public Function IndexOf(ByVal value As CodeDomClass) As Integer
        Return List.IndexOf(value)
    End Function

    Public Sub Insert(ByVal index As Integer, ByVal value As CodeDomClass)
        List.Insert(index, value)
    End Sub

    Public Shadows Sub Clear()
        MyBase.Clear()
    End Sub

    Public Function GetAttributes() As System.ComponentModel.AttributeCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetAttributes
        Return TypeDescriptor.GetAttributes(Me, True)
    End Function

    Public Function GetClassName() As String Implements System.ComponentModel.ICustomTypeDescriptor.GetClassName
        Return TypeDescriptor.GetClassName(Me, True)
    End Function

    Public Function GetComponentName() As String Implements System.ComponentModel.ICustomTypeDescriptor.GetComponentName
        Return TypeDescriptor.GetComponentName(Me, True)
    End Function

    Public Function GetConverter() As System.ComponentModel.TypeConverter Implements System.ComponentModel.ICustomTypeDescriptor.GetConverter
        Return TypeDescriptor.GetConverter(Me, True)
    End Function

    Public Function GetDefaultEvent() As System.ComponentModel.EventDescriptor Implements System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent
        Return TypeDescriptor.GetDefaultEvent(Me, True)
    End Function

    Public Function GetDefaultProperty() As System.ComponentModel.PropertyDescriptor Implements System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty
        Return TypeDescriptor.GetDefaultProperty(Me, True)
    End Function

    Public Function GetEditor(ByVal editorBaseType As System.Type) As Object Implements System.ComponentModel.ICustomTypeDescriptor.GetEditor
        Return TypeDescriptor.GetEditor(Me, editorBaseType, True)
    End Function

    Public Overloads Function GetEvents() As System.ComponentModel.EventDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetEvents
        Return TypeDescriptor.GetEvents(Me, True)
    End Function

    Public Overloads Function GetEvents(ByVal attributes() As System.Attribute) As System.ComponentModel.EventDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetEvents
        Return TypeDescriptor.GetEvents(Me, attributes, True)
    End Function

    Public Overloads Function GetProperties() As System.ComponentModel.PropertyDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetProperties
        Return Nothing
    End Function

    Public Overloads Function GetProperties(ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetProperties
        Dim pdcProperties As New PropertyDescriptorCollection(Nothing)
        For i As Integer = 0 To List.Count - 1
            Dim pdProperty As New ClassCollectionPropertyDescriptor(Me, i)
            pdcProperties.Add(pdProperty)
        Next
        Return pdcProperties
    End Function

    Public Function GetPropertyOwner(ByVal pd As System.ComponentModel.PropertyDescriptor) As Object Implements System.ComponentModel.ICustomTypeDescriptor.GetPropertyOwner
        Return Me
    End Function


End Class

<EditorBrowsable(EditorBrowsableState.Never)> _
    Public Class ClassCollectionPropertyDescriptor
    Inherits PropertyDescriptor

    Private _Collection As CodeDomClassCollection = Nothing
    Private _Index As Integer = -1

    Sub New(ByVal Collection As CodeDomClassCollection, ByVal Index As Integer)
        MyBase.New("#" + Index.ToString(), Nothing)
        _Collection = Collection
        _Index = Index
    End Sub

    Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
        Return True
    End Function

    Public Overrides ReadOnly Property ComponentType() As System.Type
        Get
            Return _Collection.GetType
        End Get
    End Property

    Public Overrides Function GetValue(ByVal component As Object) As Object
        Return _Collection(_Index)
    End Function

    Public Overrides ReadOnly Property IsReadOnly() As Boolean
        Get
            Return False
        End Get
    End Property

    Public Overrides ReadOnly Property PropertyType() As System.Type
        Get
            Return _Collection(_Index).GetType()
        End Get
    End Property

    Public Overrides Sub ResetValue(ByVal component As Object)

    End Sub

    Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)

    End Sub

    Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
        Return True
    End Function

    Public Overrides ReadOnly Property Attributes() As System.ComponentModel.AttributeCollection
        Get
            Return New AttributeCollection(Nothing)
        End Get
    End Property

    Public Overrides ReadOnly Property DisplayName() As String
        Get
            Dim item As CodeDomClass = _Collection(_Index)
            Return "Class " & _Index
        End Get
    End Property

    Public Overrides ReadOnly Property Description() As String
        Get
            Return "Defines a class document."
        End Get
    End Property

    Public Overrides ReadOnly Property Name() As String
        Get
            Return "#" + _Index.ToString()
        End Get
    End Property

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Arkitech EBC Corporation
United States United States
MS, BBA, software developer, consultant, and trainer. Specializing in building data-centric applications designed for business, university, community & faith based organizations. Started developing Excel VBA macros and never looked back. Freelance developer utilizing VB.Net, SQL Server, Microsoft Access, and ASP.Net.

Comments and Discussions