In vb.net, I'm trying to create an extension to duplicate/reverse/merge stacks. Please note that it might exists already but I'm facing an issue.
I've a module, called utility.vb that hold a whole bunch of <Extension()> like the Duplicate that I'm trying to write.
''' <summary>
''' Duplicate a stack of object to another
''' </summary>
''' <typeparam name="T">Object type in the stack</typeparam>
''' <param name="s">Stack to duplicate</param>
''' <returns></returns>
<Extension()>
Public Function Duplicate(Of T)(ByVal s As Stack(Of T())) As Stack(Of T())
Dim tmp As New Stack(Of T())
For i As Integer = s.Count - 1 To 0 Step -1
tmp.Push(s(i))
Next
Return tmp
End Function
I'm doing a various amount of Push in a Stack called labelStack. But when I call the Duplicate function from my code (because I need to re-use the same stack multiple times), it is not compiling (please note that the stack is made of own created object class)
Dim summaryStack As Stack(Of CCNode) = labelStack.Duplicate()
The error is "'Duplicate' is not a member of 'Stack(Of MyForm.CCNode)'"
I also tried to change the signature of the extension like so:
Public Function Duplicate(Of T As {New})(ByVal s As Stack(Of T())) As Stack(Of T())
But without any success.
Can someone help me (pointing out my mistake, correcting it or give me a way to achieve my need without writing the function myself)?
P.S.: I'm using Stack because I need to Pop in reverse order of my Push and it seemed appropriate.