Diego Diego - 17 days ago 75
Vb.net Question

vb.net Dictionary(Of String, Object) enum.getname()

I am doing an VB.Net WinForm Application. It is a migration of C#.

In C# I have a variable defined like this.

private static Dictionary<string, ExportFormatType> dicExtensiones =
new Dictionary<string, ExportFormatType> {
{".pdf", ExportFormatType.PortableDocFormat},
{".doc", ExportFormatType.WordForWindows},
{".xls", ExportFormatType.Excel},
{".rtf", ExportFormatType.RichText},
{".html", ExportFormatType.HTML40},
{".txt", ExportFormatType.Text}
};


And i migrated to this..

Private Shared dicExtensiones = New Dictionary(Of String, ExportFormatType) From
{{".pdf", ExportFormatType.PortableDocFormat},
{".doc", ExportFormatType.WordForWindows},
{".xls", ExportFormatType.Excel},
{".rtf", ExportFormatType.RichText},
{".html", ExportFormatType.HTML40},
{".txt", ExportFormatType.Text}}


Now I need to Loop through all ítems and get each value...

In C# is like this.

List<String> lista = new List<string>();

foreach (var item in dicExtensiones)
{
lista.Add(Enum.GetName(typeof(ExportFormatType), item.Value));
lista.Add("*" + item.Key);
}


The problem i have is that I do know how to migrate

Enum.GetName(typeof(ExportFormatType), item.Value);


to VB.Net, because
Enum.GetName
does not exists in VB.Net

How can I do it?

Answer Source

it can be like below in VB

Dim lista As List(Of [String]) = New List(Of String)()

For Each item As var In dicExtensiones
    lista.Add([Enum].GetName(GetType(ExportFormatType), item.Value))
    lista.Add("*" + item.Key)
Next