locked
Enumeration of My.Resources RRS feed

  • Question

  • User-1493523312 posted
    Hi!

    I am looking for a way to enumerate resources programmatically.
    I have found a way in the .NET 1.1-style (which I present here),
    but I would like to make use of the functionality of .NET 2.0.

    Example:
    A resource "ErrorsRes" contains a couple of string.
    I'd like to create a textbox, which enumeates the
    name and values of the elements in "ErrorsRes".

    In the philosophy of .NET 1.1, the following is a working example:

    Dim myRR As ResourceReader
    Dim myEnum As IDictionaryEnumerator
    Dim myAssem As Assembly = GetType(ResLibraryClass).Assembly

    myRR = New ResourceReader(myAssem.GetManifestResourceStream("namespace.ErrorsRes.resources"))
    myEnum = myRR.GetEnumerator()

    Me.TextBox1.Text = ""
    Do While myEnum .MoveNext
    Me.TextBox1.Text = Me.TextBox1.Text & CType(myEnum .Key, String) & "," & CType(myEnum .Value, String) & vbCrLf
    Loop
     

    My question now refers to the .NET 2.0 Framework.
    I would like to use My.Resources.ErrorsRes to somehow
    generate that list, in the sense of

    Dim myObj As .....

    For Each myObj In My.Resources.ErrorsRes
    .....
    Next

    Of course, it would be also great to enumerate the
    resources listet in My.Resources [:)], which I do in
    .NET 1.1 using

    Dim ResourceName As String
    myAssem = GetType(ResLibraryClass).Assembly

    For Each
    ResourceName In myAssem.GetManifestResourceNames
    ...
    myRR = New ResourceReader(myAssem.GetManifestResourceStream(ResourceName))
    myEnum = myRR.GetEnumerator()
    ...


    Thanks a lot,
    Cheers!



       
     
    Friday, June 16, 2006 5:25 AM

All replies

  • User1535111871 posted

    You'll want to combine the old and the new:

    Dim loEnumerator As IDictionaryEnumerator
    Dim loManager As ResourceManager
    Dim loReader As ResourceReader
    Dim lcName As String
    
    loManager = My.Resources.ErrorsRes.ResourceManager
    lcName = loManager.BaseName & ".resources"
    
    With Assembly.GetExecutingAssembly
      loReader = New ResourceReader(.GetManifestResourceStream(lcName))
    End With
    
    loEnumerator = loReader.GetEnumerator
    
    While loEnumerator.MoveNext
      ...
    End While
    
    loReader.Close()
    

    HTH

    Friday, August 7, 2009 12:04 AM