views:

58

answers:

1

Is there a better (shorter) method to retrieve the NeutralResourcesLanguageAttribute of an assembly than using reflection as implemented below?

Public Function GetNeutralResourcesLanguage() As String
    Dim assembly = System.Reflection.Assembly.GetExecutingAssembly
    Dim attributes = assembly.GetCustomAttributes(GetType(System.Resources.NeutralResourcesLanguageAttribute), False)
    If attributes.Length <> 1 Then
        Return "en-US"
    End If

    Dim attribute = CType(attributes(0), System.Resources.NeutralResourcesLanguageAttribute)
    Return attribute.CultureName
End Function
A: 

Most (if not all) .Net attributes are only accessible using reflection (Attributes (C# Programming Guide)) so the method that you're using, AFAIK, is the best and only way.

Chris Haas