Create an IDocument instance from a single .cs file

Answered Create an IDocument instance from a single .cs file

  • Tuesday, August 14, 2012 9:15 PM
     
     

    Hi There,

    I try to build a novel refactoring tool that performs refactoring on source code files that are not existing in the current work space. Is there a way I can create an IDocument instance from these source code files?

    Thanks very much!

    Xi Ge 

All Replies

  • Friday, August 17, 2012 6:23 PM
     
     Answered

    The document instances are part of the solution/project/document model, so you can only have a document instance if you manually add one to a solution instance.  So you can either take the solution that the workspace has and add your document to it (it will then be in a separate immutable branch of the solution that workspace doesn't directly know about) or you can create your own separate solution instance and add your document to that.

    var solutionId = SolutionId.Create();
    var projectId = ProjectId.Create(solutonId);
    var documentId = DocumentId.Create(projectId);

    var solution = Solution.Create(solutionId).AddProject(projectId, ...).AddDocument(documentId, ...);

    var doc = solution.GetDocument(documentId);


    Wayward LINQ Lacky

  • Sunday, August 19, 2012 3:13 AM
     
     

    Hi Matt,

    Thanks for the reply! They do help a lot!

    Xi