My.Application equivalent in c#

E

Erick

I'm converting some code which calls the Visual Studio extensibility
classes.
In vb.net one of the paramaters is the reference to the application it
self which is passed through the My.Application object.

When i look through MSDN I get that the
System.Windows.Application.Current is suppose to be the equivalent
However, the System.Windows.Application.Current only exists in
Silverlight

"This" passess a reference of the current object and not the entire
app.

So how do i pass a reference of the current application in C#

regards
 
P

Peter Duniho

Erick said:
I'm converting some code which calls the Visual Studio extensibility
classes.
In vb.net one of the paramaters is the reference to the application it
self which is passed through the My.Application object.

When i look through MSDN I get that the
System.Windows.Application.Current is suppose to be the equivalent
However, the System.Windows.Application.Current only exists in
Silverlight

Actually, that's not true. It's available to any application
referencing PresentationFramework.dll. That would generally be WPF
applications.
"This" passess a reference of the current object and not the entire
app.

So how do i pass a reference of the current application in C#

That all depends on what your idea of an "application" is. There are a
number of classes named "Application", all of which slightly diferent.

The VB.NET "My.Application" is a VB.NET-specific thing. You can
actually get the exact same implementation if you reference the
Microsoft.VisualBasic.ApplicationServices namespace and the
Microsoft.VisualBasic.dll DLL. But, the same _functionality_ is also
(for the most part) provided by specific .NET classes, and it is
generally preferable to use those classes rather than drag the
VB.NET-specific library into a C# application.

If you can post the code that uses the My.Application object in VB.NET,
it should be possible to point out the functional equivalent using only
regular .NET library objects.

Pete
 
G

Gregory A. Beamer

I'm converting some code which calls the Visual Studio extensibility
classes.
In vb.net one of the paramaters is the reference to the application it
self which is passed through the My.Application object.

For a quick fix, you can use the Microsoft.VisualBasic.ApplicationServices
namespace, as Peter has mentioned. This tags on the VB bits, which may not
be your final option (the weight of the extra assembly should be minimal).

You should also be able to get the Application instance (System.Windows
namespace) from Context and do the same thing, although this may require
more code changes than you want to make in the near future. I would head
this direction, ultimately, as I am not fond of leaving in references for
the sole purpose of using an application object.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top