Extending My

time to read 3 min | 535 words

Okay, I'm not a VB.Net guy, but I saw today something that just drove me crazy. Today during his talk, Jackie showed us how he can extend My with a partial class. And that is not something that I've ever seen before. He said that it was because the My classes were partial classes, but doesn't ring quite right to me. I tried to copy what he did, but I can't do it in VB.Net or C#.

The code from the session is not up yet, and it's driving me nuts. Any ideas? What Jackie did was to add a Nickname property the My.Computer. I would love to know how this was done.

After googling (found one relevant result):

Namespace My
    Partial Friend Class MyComputer
        Private _phone As Integer
        Public Property Phone() As Integer
            Get
                Return _phone
            End Get
            Set(ByVal value As Integer)
                _phone = value
            End Set
        End Property
    End Class   
End Namespace

This seems to do the trick, but I'm not happy with it. I'll be the first to admit that I'm not a VB.Net expert (or even vagualy familiar), I seems to be missing something.

  • I can't tell if it's unique to My or if it's a general .Net thing, I didn't manage to create a cross assembly partial type when I tried.
  • I don't understand why I need the Friend declaration there, it fails compilation if I try to make it public, but my understanding of VB.Net says that Friend == internal, and I can't see how the declarations would be matched.

Anyone can pipe in with the info? I searched, but there seems to be little info about this.