views:

145

answers:

4

No I'm not being a wise guy ...

For those fortunate enough to not know the My class: It's something that was added in VB 2005 (and doesn't exist in C#) and is best described as a 'speeddial for the .net framework'. Supposed to make life easier for newbies who won't read which framework classes they should be using

Dim contents As String
contents = My.Computer.FileSystem.ReadAllText("c:\mytextfile.txt")

Instead of this:

Dim contents As String
contents = IO.File.ReadAllText("c:\mytextfile.txt")

My Question: Where is the MSDN documentation page for which speeddial button maps to what.. ?
By choosing the name of the feature as My - they've just made searching a whole lot more fun that it needs to be. I need to code in C# and can't bear the fun of translating the training/how-to office prog videos which exclusively deal in VB.

More on this from the Dans

Juval Lowy ported My as That in C# as an interim solution. Don't ask me why...

+2  A: 

It's the "My namespace" rather than the "My class" which may aid searching.

So far I've found this: http://msdn.microsoft.com/en-us/vbasic/ms789188.aspx but it's not ideal. Looking for more...

EDIT: I think "Developing with My" is effectively the root of the documentation.

Jon Skeet
A: 

This looks promising - it is a detailed account of the MyServices area (that provides My in VB)

Some more is here.

Marc Gravell
A: 

Different features inside the My namespace behave very differently and are implemented using different techniques. There's not “one” documentation for them, unfortunately.

Many of the shortcut methods refer to classes within the Microsoft.VisualBasic.dll. You can of course reference this from C#.

Some mappings (by no means complete):

  • My.Application => Microsoft.VisualBasic.ApplicationServices.ApplicationBase

    This class is inherited from to produce the Application Framework of VB.

  • My.Computer => Microsoft.VisualBasic.Devices.ServerComputer
  • My.User => Microsoft.VisualBasic.ApplicationServices.User
  • My.Settings => Maps directly to C#'s RootNamespace.Properties.Settings
  • My.Resources => Maps directly to C#'s RootNamespace.Properties.Resources
Konrad Rudolph
Gishu, it depends on how you add the resources. If you use the auto-generated `Resources.resx` file by adding your resources via the project properties dialog, you'll end up with my solution.
Konrad Rudolph
How did you compile this list? corr code for Me.CustomXMLParts.Add(My.Resources.Data) is this.CustomXMLParts.Add(Resources.Data, ... [RootNS].Properties.Resources.Data doesn't exist. Resources is the auto-gen helper class for Resources.resx. [RootNS].Resources.Data is where it is at.
Gishu
+1  A: 

The official reference for the My namespace can be found here on MSDN.

Unfortunately, it doesn't describe which 'real' Framework features the My shortcuts map to (although this isn't too hard to figure out in most cases).

As a further annoyance, the source code isn't released as part of the .NET Reference Source either (same situation as with Microsoft.VisualBasic, even though being able to check the source would do a lot to demystify this part of the Framework...)

mdb