tags:

views:

42

answers:

2

Writing a .NET DLL how do I find Application.ProductName?

EDIT:
Obviously, importing Windows.Forms could solve the problem, but my DLL have nothing to do with Windows Forms.

+2  A: 

Tested in C#. Should be fine in VB at least.. not sure about c++

System.Windows.Forms.Application.ProductName
gbogumil
heh. You impose me to import Windows.Forms in a .DLL
serhio
+3  A: 

The Application class just needs a reference to System.Window.Forms. So the simpler way is to add that reference in your *.dll and use the property.

However if you are not allowed to reference the Windows Forms library you can somewhat replicate the functionality in a custom class of yours and read the AssemblyProductAttribute from the assembly you consider to be your application. For a console application you would consider the assembly returned from Assembly.GetEntryAssembly to be your application.

João Angelo
hmm, what should be "worst" to import: Windows.Forms or System.Reflection?
serhio
Taking in consideration that `Application.ProductName` uses `System.Reflection` the only choice to make is: Should I reference Windows Forms and get cleaner and tested code or just add more code to maintain?
João Angelo
okey, okey, referenced Windows.Forms :)
serhio