将 Jscript 转换为 C# 以创建 Sparx EA 插件
Converting Jscript into C# to create Add-in for Sparx EA
我在 Jscript 中编写代码以在 EA 项目浏览器中扫描图表,然后创建关于现有元素的元素列表。该代码可以正常工作。目前,当我尝试将我的代码 (Jscript) 转换为 C# 以为 Enterprise Architect 创建自定义插件时遇到问题。
这是我在 Jscript 中的代码的一部分:
var theModel as EA.Package;
theModel = Repository.Models.GetAt( 0 );
// Iterate through all views (top level packages) in the model
var viewEnumerator = new Enumerator( theModel.Packages );
while ( !viewEnumerator.atEnd() )
{
var currentView as EA.Package;
currentView = viewEnumerator.item();
// Add the name of this view to the output window
Session.Output( currentView.Name );
// Iterate through all diagrams in this view
viewEnumerator.moveNext();
}
这是c#中转换后的代码:
EA.Package theModel;
theModel = Repository.Models.GetAt( 0 );
// Iterate through all views (top level packages) in the model
var viewEnumerator = new Enumerator( theModel.Packages );
while ( !viewEnumerator.atEnd() )
{
EA.Package currentView;
currentView = viewEnumerator.item();
// Add the name of this view to the output window
MessageBox.Show( currentView.Name );
// Iterate through all diagrams in this view
viewEnumerator.moveNext();
}
但是,我遇到以下问题:
var viewEnumerator = new Enumerator( theModel.Packages );
错误是:
The type or namespace name 'Enumerator' could not be found (are you missing a using directive or an assembly reference?)
实际上,我不知道如何在 C# 中创建类似的东西
有什么建议
您可以使用 foreach
循环代替 Enumerator
EA.Package theModel;
theModel = Repository.Models.GetAt( 0 );
// Iterate through all views (top level packages) in the model
foreach( EA.Package currentView in theModel.Packages )
{
// Add the name of this view to the output window
MessageBox.Show( currentView.Name );
}
确保键入 currentView(不要使用 var
),因为 EA.Collection 不是强类型。
我在 Jscript 中编写代码以在 EA 项目浏览器中扫描图表,然后创建关于现有元素的元素列表。该代码可以正常工作。目前,当我尝试将我的代码 (Jscript) 转换为 C# 以为 Enterprise Architect 创建自定义插件时遇到问题。
这是我在 Jscript 中的代码的一部分:
var theModel as EA.Package;
theModel = Repository.Models.GetAt( 0 );
// Iterate through all views (top level packages) in the model
var viewEnumerator = new Enumerator( theModel.Packages );
while ( !viewEnumerator.atEnd() )
{
var currentView as EA.Package;
currentView = viewEnumerator.item();
// Add the name of this view to the output window
Session.Output( currentView.Name );
// Iterate through all diagrams in this view
viewEnumerator.moveNext();
}
这是c#中转换后的代码:
EA.Package theModel;
theModel = Repository.Models.GetAt( 0 );
// Iterate through all views (top level packages) in the model
var viewEnumerator = new Enumerator( theModel.Packages );
while ( !viewEnumerator.atEnd() )
{
EA.Package currentView;
currentView = viewEnumerator.item();
// Add the name of this view to the output window
MessageBox.Show( currentView.Name );
// Iterate through all diagrams in this view
viewEnumerator.moveNext();
}
但是,我遇到以下问题:
var viewEnumerator = new Enumerator( theModel.Packages );
错误是:
The type or namespace name 'Enumerator' could not be found (are you missing a using directive or an assembly reference?)
实际上,我不知道如何在 C# 中创建类似的东西
有什么建议
您可以使用 foreach
循环代替 Enumerator
EA.Package theModel;
theModel = Repository.Models.GetAt( 0 );
// Iterate through all views (top level packages) in the model
foreach( EA.Package currentView in theModel.Packages )
{
// Add the name of this view to the output window
MessageBox.Show( currentView.Name );
}
确保键入 currentView(不要使用 var
),因为 EA.Collection 不是强类型。