Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Making an object available in a NameObjectCollectionBase
Message
De
28/01/2011 11:20:51
 
 
À
27/01/2011 17:45:19
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01497597
Message ID:
01497663
Vues:
38
I'm pretty sure that you use an instance of your oApp object throughout your app, but is that class a singleton where you have a shared/static method to get the instance? If so, then you could access it like this:

lnLanguage = MyAppClass.GetoAppInstance().nLanguage

~~Bonnie



>I would like to know if it is possible to make an object available in a NameObjectCollectionBase.
>
>For example, for my label design, I can do things like this for those commonly used labels that I prefer to initialize when the application starts:
>
>
>oApp.Labels("Company").Title_E
>oApp.Labels("Company").Title_F
>
>
>...which would return the company label in English and in French.
>
>And, I would like to be able to do this:
>
>
>oApp.Labels("Company").Title
>
>
>...which would then return the company label in the language of the application object, which is oApp.nLanguage.
>
>My Labels NameObjectCollectionBase is defined like this:
>
>
>    ' Label class
>    Public Class Label
>        Private cName As String = ""
>        Private cTitle As String = ""
>        Private cTitle_E As String = ""
>        Private cTitle_F As String = ""
>        Private cTitle_S As String = ""
>        Private cTitle_P As String = ""
>
>        ' expC1 Name
>        ' expC2 Title in English
>        ' expC3 Title in French
>        ' expC4 Title in Spanish
>        ' expC5 Title in Portuguese
>        Public Sub New(ByVal tcName As String, ByVal tcTitle_E As String, _
>         ByVal tcTitle_F As String, ByVal tcTitle_S As String, _
>         ByVal tcTitle_P As String)
>
>            cName = tcName
>            cTitle_E = tcTitle_E
>            cTitle_F = tcTitle_F
>            cTitle_S = tcTitle_S
>            cTitle_P = tcTitle_P
>
>        End Sub
>
>        Public ReadOnly Property Name As String
>            Get
>                Return cName
>            End Get
>        End Property
>
>        Public ReadOnly Property Title As String
>            Get
>                Dim lcTitle As String = ""
>                Dim lnLanguage As Integer = 0
>
>                ' In the following line, I need to find a way to have oApp available here so I can get
>                ' the nLanguage property value and return the title of the label based on it.
>
>                ' lnLanguage = oApp.nLanguage
>
>                ' Based on the language
>                Select Case lnLanguage
>
>                    ' English
>                    Case 1
>                        lcTitle = Title_E
>
>                        ' French
>                    Case 2
>                        lcTitle = Title_F
>
>                        ' Spanish
>                    Case 3
>                        lcTitle = Title_S
>
>                        ' Portuguese
>                    Case 4
>                        lcTitle = Title_P
>
>                End Select
>
>                Return lcTitle
>            End Get
>        End Property
>
>        Public ReadOnly Property Title_E As String
>            Get
>                Return cTitle_E
>            End Get
>        End Property
>
>        Public ReadOnly Property Title_F As String
>            Get
>                Return cTitle_F
>            End Get
>        End Property
>
>        Public ReadOnly Property Title_S As String
>            Get
>                Return cTitle_S
>            End Get
>        End Property
>
>        Public ReadOnly Property Title_P As String
>            Get
>                Return cTitle_P
>            End Get
>        End Property
>
>    End Class
>
>    Public Class Labels
>        Inherits System.Collections.Specialized.NameObjectCollectionBase
>
>        Public Overloads Sub Add(ByVal Label As Label)
>            BaseAdd(Label.Name, Label)
>        End Sub
>
>        Default Public Overloads ReadOnly Property Item(ByVal Title As String) As Label
>            Get
>                Return CType(BaseGet(Title), Label)
>            End Get
>        End Property
>
>    End Class
>
>
>The problem is that I do not want to pass oApp as a parameter to this property. The goal of this is to be able to have this collection to recognize what is the current oApp.nLanguage value by itself so to return the proper string as per the language.
>
>Is this possible?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform