小编nam*_*los的帖子

VS2008 UnitTesting - 带有Office应用程序对象的分离RCW(PowerPoint等)

背景

  • 我通过C#自动化PowerPoint 2007
  • 我正在使用Visual Studio的内置单元测试(Microsoft.VisualStudio.TestTools.UnitTesting)为我的代码编写单元测试
  • 我在自动化Office 2007应用程序方面经验丰富

我的问题

  • 当我运行我的单元测试时,第一个单元测试方法运行正常,之后都有关于分离的RCW的错误
  • 我正在为要共享的测试方法创建一个PowerPoint的静态实例,但似乎应用程序RCW在第一个测试方法运行后被分离

来源代码

    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    namespace TestDemo
    {



        [TestClass]
        public class UnitTest1
        {
            private static Microsoft.Office.Interop.PowerPoint.ApplicationClass 
              g_app = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();

            private TestContext testContextInstance;

            public TestContext TestContext
            {
                get
                {
                    return testContextInstance;
                }
                set
                {
                    testContextInstance = value;
                }
            }



            [TestMethod]
            public void Test01()
            {
                g_app.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue;
            }

            [TestMethod]
            public void Test02()
            {
                g_app.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue;
            }
        }

    }
Run Code Online (Sandbox Code Playgroud)

错误信息

Test method TestDemo.UnitTest1.Test02 threw …
Run Code Online (Sandbox Code Playgroud)

unit-testing mstest ms-office rcw visual-studio

7
推荐指数
1
解决办法
1505
查看次数

有没有更简单的方法在Powershell v2中使用扩展方法

背景

这篇文章解释了如何在Powershell中使用扩展方法

http://community.bartdesmet.net/blogs/bart/archive/2007/09/06/extension-methods-in-windows-powershell.aspx

将此与C#中的人员进行比较 - 他们添加"使用SomeAssembly"并加载所有扩展方法.

我的问题

这是否变得更简单Powershell 2.0.如果是这样,人们如何在Powershell 2.0中使用扩展方法?我检查了公开可用的文档并安装了CTP,但没有看到任何有用的信息.

powershell extension-methods

6
推荐指数
1
解决办法
2534
查看次数

使用Dynamics AX 2009业务连接器创建表和检索查询结果

我正在编写一个C#命令行工具来从AX获取数据并向AX添加数据(创建新表).

从AX表中获取数据很简单,并在此处记录:http://msdn.microsoft.com/en-us/library/cc197126.aspx

将数据添加到现有表格也很简单:http://msdn.microsoft.com/en-us/library/aa868997.aspx

但我无法弄清楚如何做两件事:

  • 创建一个新的 AX表
  • 从AX查询中检索数据

有人可以分享一些示例代码或指出从哪里开始寻找.我在谷歌和MSDN上的搜索没有透露太多.

注意:我不是经验丰富的AX或ERP开发人员.

c# axapta dynamics-ax-2009

6
推荐指数
2
解决办法
6387
查看次数

Winforms:删除由Visual Studio for Windows Forms创建的自动创建的Dispose()方法中的代码是否安全

背景

在Visual Studio 2008中创建一个新的Windows窗体应用程序,这将创建一个名为"Form1"的类的骨架项目.VS2008自动创建Dispose()方法.

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
Run Code Online (Sandbox Code Playgroud)

我徘徊在一个同事办公室(一个高级开发人员) - 好人,聪明,良好的聊天设计技巧 - 但我注意到他正在输入的内容 - 因为他导航了代码库,他删除了VS2008创建的Dispose()方法的这一部分对于表格.

        if (disposing && (components != null))
        {
            components.Dispose();
        }
Run Code Online (Sandbox Code Playgroud)

所以,我问他为什么,他说没有必要保留它.

问题

  • 删除此代码是否安全?
  • 将它留在或删除它的优点/缺点是什么?

c# dispose winforms

4
推荐指数
2
解决办法
454
查看次数