tags:

views:

38

answers:

1

Is it possible to automatically insert a Code Snippet when an interface is implemented? If so, how do you do it? I am looking for something similar to when you implement IDispoable in VB.

e.g.

I have the following Interface

Public Interface ITransferable

    ReadOnly Property TransferParameters() As Object

End Interface

I also have a Code Snippet as follows

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Transfer Parameter Snippet</Title>
      <Author>RMC</Author>
      <Description>Transfer Parameter Snippet used when implementing the ITRansferable Interface</Description>
    </Header>
    <Snippet>
      <Code Language="VB" Kind="" Delimiter="$">
        <![CDATA[
          Private m_oTransferParameters As Object

          Public Class InputParameters
              'Add Input Parameter declaration/s here
          End Class

          Public Class OutputParameters
              'Add Output Parameter declaration/s here
          End Class

          Public ReadOnly Property TransferParameters() As Object Implements ITransferable.TranferParameters

              Get
                  Return m_oTransferParameters 
              End Get

          End Property
        ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

So, what I want to happen, is when the ITransferable Interface is implemented, it injects the code in the code snippet into the class implementing the interface, such as

Public Class NewClass()
    Implements ITransferable

    Private m_oTransferParameters As Object

    Public Class InputParameters
        'Add Input Parameter declaration/s here
    End Class

    Public Class OutputParameters
        'Add Output Parameter declaration/s here
    End Class

    Public ReadOnly Property TransferParameters() As Object Implements ITransferable.TranferParameters

        Get
             Return m_oTransferParameters 
         End Get

    End Property

End Class

This will be used by web forms when transfering parameters from one page to the next using Server.Transfer

A: 

Well, after a lot of digging around on the net, and not coming up with much, I have ended up using a custom item template to accomplish what i needed to do as I want all web forms to inherit from the ITransferable Interface, now when a developer wants to create a new web form, they select my custom one from the 'Add New Item' popup, this then creates a web page with all the code in that I required. I hope this is of some use to someone.

Robert Chelton