Partial methods idea for the class wrappers generated by Linq2Xsd

Aug 22, 2011 at 12:47 PM

Hi,

Had an idea while trying to marshal Linq2Xsd classes across the COM barrier to VB6 (fun!)

As the IList<T> properties won't marshal, I added a concrete class that wrapped an IList<T> for a specific instance and added a property of that type.

However I can't instantiate the property because the constructor is in the generated source code.

However, instead of the constructor being this:

 

        /// <summary>
        /// <para>
        /// Regular expression: (datafile+)
        /// </para>
        /// </summary>
        public datafilesLocalType() {
        }

 

It could generate this:

 

        /// <summary>
        /// <para>
        /// Regular expression: (datafile+)
        /// </para>
        /// </summary>
        public datafilesLocalType() {
            OnCreated();
        }

        public partial void OnCreated();

 

And I could write this in my partial class:

    [Guid("DC5755A5-46D8-4f3a-824A-56C7C646453D")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public partial class datafilesLocalType
    {
        public partial void OnCreated()
        {
            datafile2 = new datafileList();
        }

Also I've added this is our local version of LinqToXsd 1.1.0:

//Defines interfaces involving FSM executions
namespace Xml.Schema.Linq {
    [Guid("3C59C30B-00C2-4ae2-B6FF-E4E3BCD91118")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public partial class XTypedElement {

You need that Guid and ClassInterface to attribute for the COM bit to work, as everything is based off of XTypedElement

Oh, and this:

[assembly: ComVisible(true)]
If I wanted to change the code myself to write the different constructor, where would I find it in the LinqToXsd source code?

Regards,

James.