0
我正在關注this鏈接中的代碼示例。未能初始化DTE對象
我打在第二行一個障礙右:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using EnvDTE;
namespace TwinCAT_Automation_Interface
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
//Creating TwinCAT Projects via templates (Recommended)
Type myType = System.Type .GetTypeFromProgID ("VisualStudio.DTE.12.0");
dynamic myDTE = System.Activator.CreateInstance (myType); //error right here
}
}
誤差表示:
錯誤1的字段初始不能引用非靜態字段, 方法,或屬性「 TwinCAT_Automation_Interface.Main.myType'
我究竟做錯了什麼?這是相同的代碼片段;我只是修改了一下。請幫忙!!!!
OK,我把它固定,改成如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using EnvDTE;
namespace TwinCAT_Automation_Interface
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
public void myMethod()
{
//Creating TwinCAT Projects via templates (Recommended)
Type myType = System.Type .GetTypeFromProgID ("VisualStudio.DTE.12.0");
dynamic myDTE = System.Activator.CreateInstance (myType); // dynamic linking for DTE-object
}
}
}
的解釋是this鏈接。這是一個編譯器錯誤。