Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My winforms app gets an IWorkspaceName from an IDatasetName via the GxObject selected in a GxDialog. I want to pass it across to a worker thread for opening.

I know how to write multithreaded arcobjects code - particularly the need to create the workspace factory class on the worker thread but my app makes no assumptions as to the type of workspace factory. I've considered passing it as a serialized xml string, but the documentation seems strangely vague on this topic. Does anyone have code to do this?

On preview,

I'm asking much the same as this question. Has anyone cracked the xml serialization / deserialization? It seems the simplest way to go or is there a better way?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

See my example code below, it will enable you to deserialize instance of IWorkspaceName on the other thread from the XML produced by the serialization method.

It can be easily modified to allow serialization and deserialization of any ArcObject which implements ESRI.ArcGIS.esriSystem.IXMLSerialize.

    private static string GetWorkspaceNameAsXmlString(IWorkspaceName workspaceName)
    {
        if (workspaceName == null) throw new ArgumentNullException("workspaceName");

        var xmlStream = new XMLStreamClass();
        var xmlWriter = new XMLWriterClass();
        var xmlSerializer = new XMLSerializerClass();

        xmlWriter.WriteTo(xmlStream);
        xmlSerializer.WriteObject(xmlWriter, null, null, string.Empty, string.Empty, workspaceName);

        return xmlStream.SaveToString();
    }

    private static IWorkspaceName GetWorkspaceNameFromXmlString(string xml)
    {
        if (xml == null) throw new ArgumentNullException("xml");

        var xmlStream = new XMLStreamClass();
        var xmlReader = new XMLReaderClass();
        var xmlSerializer = new XMLSerializerClass();

        xmlStream.LoadFromString(xml);
        xmlReader.ReadFrom(xmlStream);

        return xmlSerializer.ReadObject(xmlReader, null, null) as IWorkspaceName;
    }
share|improve this answer
    
Thanks. Exactly what I needed. –  nef001 Nov 9 '10 at 23:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.