Question Auto generating interface methods

olsonpm

Well-known member
Joined
Aug 24, 2010
Messages
46
Programming Experience
Beginner
I have used netbeans for some time now, and was assuming that visual studio would have some sort of feature to auto-fill the methods which my class is supposed to implement. I searched a bit through the forum/google, but could only find this link.

Auto insertion of interface members in Visual Studio 2010

I don't understand what it means by "only stubbing the members if it is considered the active document." It seems like i should be able to right click the error and choose "add interface methods". Any help would be appreciated.

Thanks,
Phil
 
All you have to do is hit the Enter key after the name of the interface. So, you type:
VB.NET:
Public Class ThingList
and hit Enter and you end up with:
VB.NET:
Public Class ThingList

End Class
Then you type to get this:
VB.NET:
Public Class ThingList
    Implements IList
End Class
and hit Enter and you get this:
VB.NET:
Public Class ThingList
    Implements IList

    Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements System.Collections.ICollection.CopyTo

    End Sub

    Public ReadOnly Property Count As Integer Implements System.Collections.ICollection.Count
        Get

        End Get
    End Property

    Public ReadOnly Property IsSynchronized As Boolean Implements System.Collections.ICollection.IsSynchronized
        Get

        End Get
    End Property

    Public ReadOnly Property SyncRoot As Object Implements System.Collections.ICollection.SyncRoot
        Get

        End Get
    End Property

    Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator

    End Function

    Public Function Add(ByVal value As Object) As Integer Implements System.Collections.IList.Add

    End Function

    Public Sub Clear() Implements System.Collections.IList.Clear

    End Sub

    Public Function Contains(ByVal value As Object) As Boolean Implements System.Collections.IList.Contains

    End Function

    Public Function IndexOf(ByVal value As Object) As Integer Implements System.Collections.IList.IndexOf

    End Function

    Public Sub Insert(ByVal index As Integer, ByVal value As Object) Implements System.Collections.IList.Insert

    End Sub

    Public ReadOnly Property IsFixedSize As Boolean Implements System.Collections.IList.IsFixedSize
        Get

        End Get
    End Property

    Public ReadOnly Property IsReadOnly As Boolean Implements System.Collections.IList.IsReadOnly
        Get

        End Get
    End Property

    Default Public Property Item(ByVal index As Integer) As Object Implements System.Collections.IList.Item
        Get

        End Get
        Set(ByVal value As Object)

        End Set
    End Property

    Public Sub Remove(ByVal value As Object) Implements System.Collections.IList.Remove

    End Sub

    Public Sub RemoveAt(ByVal index As Integer) Implements System.Collections.IList.RemoveAt

    End Sub
End Class
 
heh - I see the problem was a result of me playing around with vb.net. I happened to add the interface after coding the classes. Is there no manual way of generating the same code?
 
That doesn't make much sense. If the code is generated for you then it's automatic. If it's manual then you write it yourself.

You can add the Implements line and then hit Enter any time you like. It doesn't matter that the class already contains code.
 
I'm very sorry - I guess I simply wasn't pressing enter before? I guess a coding habit is for me to space out code before inserting my text. I don't know why. You are correct though.
 
Back
Top