Passing Structures Through Pipeline

Sep 4, 2008 at 4:42 PM
I have a bundles of data which are passed as parameters to some functions and returned as output from some functions. The bundle itself has no processing, so it could be defined as a structure as easily as a class/interface.

What is the best way to pass this bundle through the Pipeline? Using an Interface appears to have the overhead of needing an extraneous implementation class on the AddIn side. However, I can't get a Structure to be accepted by the PipelineBuilder.

If I specify my bundle as an Interface in my contracts, it looks like I need to create a class on the add-in side to implement the generated AddInViews Interface.
Public Interface IMyBundleAsContract
    Interits System.AddIn.Contract.IContract
    Property Name() as String
    Property Value() as Object
End Interface

If I specify my bundle as a Structure in my contracts, the PipelineBuilder is indicating I need exactly one constructor (from ValidateStructContract).
Public Structure IMyBundleAsStructure
    Dim m_Name as String
    Dim m_Value as Object
End Structure

Gary Geniesse
Sep 8, 2008 at 10:27 AM
Hi Gary,

Passing as a structure means you're passing by value, whereas defining contracts will have by-reference semantics. Passing as contracts gives you greater flexibility with respect to versioning over time, but at the cost of complexity.

I don't use PipelineBuilder, so can't really comment on how well it handles structures.

Sep 9, 2008 at 8:36 PM
Hi Gary,

You shouldn't be using Object in a struct. You should instead use a serializable type from a framework assembly.

As for the error message, have you tried adding a constructor like the following?

Public Structure IMyBundleAsStructure



Public Sub New(ByVal name As String, ByVal value As Object)


m_Name = name

m_Value = value


End Sub



Dim m_Name As String



Dim m_Value As Object



End Structure





Sep 10, 2008 at 10:32 PM
Thanks for the heads up on the Object, it was not necessary so I got rid of it.

As for adding a New statement to the contract, I wasn't expecting I could put code in the Structure (in C++, a struct is just a storage definition so I was confused).

Just in case someone else looks at this, there are two other things you need to do to make a structure work: make it Serializable and have a Property with the exact same name as the constructor parameter. Here's a simplified one parameter example.

<Serializable()> _
Public Structure IMyStructure
    Dim m_Name As String

    Public Sub New(ByVal Name As String)
        m_Name = newName
    End Sub

    Public Property Name() As String
            Name = m_Name
        End Get
        Set(ByVal value As String)
            m_Name = value
        End Set
    End Property
End Structure