代码之家  ›  专栏  ›  技术社区  ›  Binito Thomas

将Jscript转换为C#以创建Sparx EA的插件

  •  2
  • Binito Thomas  · 技术社区  · 8 年前

    我用Jscript编写了代码,用于扫描EA项目浏览器中的图表,然后创建一个关于现有元素的元素列表。代码可以正常工作。目前,当我试图将代码(Jscript)转换为C#以创建企业架构师的自定义插件时,我遇到了一个问题。

    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 );
    

    找不到类型或命名空间名称“Enumerator”(是否缺少using指令或程序集引用?)

    实际上,我不知道如何在C中创建类似的东西#

    有什么建议吗

    1 回复  |  直到 8 年前
        1
  •  1
  •   Geert Bellekens    8 年前

    你可以使用 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 );
    }
    

    var )作为EA。集合不是强类型的。