jeudi 22 avril 2021

Using A VSIX is it possible to create a Object from the Project That has a Extension

What I need was to Create an Instance of a C# class in the Main Project using a VSIX extension. Is this Possible?

Example:- A project this has my extension installed. When extension Invoke it Should create an Instance of that Open File. Inside the Vsix project in order to use those methods for another purpose.

Here What I was tried;

     public Void ExecuteCommand(SaveCommandArgs args, CommandExecutionContext executionContext)
    {
        ThreadHelper.ThrowIfNotOnUIThread();

      
        if (args.SubjectBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDoc))
        {
            var filePath = textDoc.FilePath;
             // Here I get the Open File Locatiob
            var dte = Package.GetGlobalService(typeof(DTE)) as DTE;
            ProjectItem item = dte.Solution?.FindProjectItem(filePath);


            var name = Path.GetFileNameWithoutExtension(filePath);
            
             // test is the project I used for Extension. namespace Test in the project that used the Extension.
          // Here When I tried to create a object from that class In give me assembly error. Activator point to the Current VSIX assembly not the Project  assembly we want
            object obj = ((ObjectHandle)Activator.CreateInstance(null, "Test."+name)).Unwrap();
            Type type = obj.GetType();

           

            
        }}

So what I really want to know What I am trying is possible or Not? if is it possible how to get that assembly here or is there any other better way to do this?





Aucun commentaire:

Enregistrer un commentaire