Detecting File Types

I'm writing a ReSharper plugin for the Spark View Engine and I need to be able to detect the type of file I'm on.
Example, if I'm on a .spark file I want to be able to perform some actions. If I'm on any other file type I want to perform some other action.

How can I do this?  What libraries do I need to look into to perform this?

Thanks    

1 comment

I've done this.  Here's what I did:

In my class that derives CSharpDaemonStageBase, the CreateProcess method override tests the process.ProjectFile.Name property to determine the extension.  In my case, if the extension is ".cs", I return an instance of my CSharpDaemonProcess class.  If the extension is ".xml", I return an instance of my XmlDaemonProcess class.  Both are instanced with the IDaemonProcess instance that was passed to my CreateProcess method override.  My DaemonProcess classes implement IDaemonStageProcess and use various highlighter classes to build up a collection of HighlightingInfo instances.  In the Execute method of my DaemonProcess classes, I call the "commiter" delegate, passing an instance of DaemonStageResult initialized with my collection of HighlightingInfos.


[DaemonStage(StagesBefore = new Type[] { typeof(UnsafeContextCheckingStage) },
StagesAfter = new Type[] { typeof(LanguageSpecificDaemonStage) })]
public class DaemonStage : CSharpDaemonStageBase
{

     public override IDaemonStageProcess CreateProcess(IDaemonProcess process, DaemonProcessKind processKind)
     {
          if (processKind != DaemonProcessKind.VISIBLE_DOCUMENT)
          {
               return null;
          }



 


          if (process.ProjectFile.Name.EndsWith(".xml"))

          {
               return new XmlFileDaemonProcess(process);
          }

          ... handle .cs files the same way...

          return null;
     }
}



0

Please sign in to leave a comment.