如何在PowerShell中使用HTML Tidy .NET DLL包装器?

时间:2009-09-28 13:52:38

标签: .net windows powershell htmltidy

我正在尝试在PowerShell 2.0中使用HTML Tidy .NET wrapper

以下是使用C#(包装分发中包含的TestIt.cs)的工作示例:

using Tidy;
Document tdoc = new Document();

我在PowerShell中这样做:

[Reflection.Assembly]::LoadFile("C:\Users\e-t172\Desktop\Tidy.NET\Tidy.dll")
New-Object Tidy.Document

我收到以下错误:

New-Object : Constructor not found. Cannot find an appropriate constructor for type Tidy.Document.
At line:1 char:11
+ New-Object <<<<  Tidy.Document
    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand

其他信息:

> [Reflection.Assembly]::LoadFile("C:\Users\e-t172\Desktop\Tidy.NET\Tidy.dll").getTypes()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    ITidyDocumentEvents
True     True     TidyReportLevel                          System.Enum
True     True     __MIDL_ITidyDocument_0008                System.Enum
True     False    DocumentClass                            System.__ComObject
True     False    ITidyDocumentEvents_Event
True     True     ITidyDocumentEvents_OnMessageEventHan... System.MulticastDelegate
True     False    Document
True     False    ITidyDocument
True     True     TidyOptionId                             System.Enum
True     True     __MIDL_ITidyDocument_0002                System.Enum
False    False    ITidyDocumentEvents_SinkHelper           System.Object
False    False    ITidyDocumentEvents_EventProvider        System.Object

发生了什么事?

1 个答案:

答案 0 :(得分:6)

尝试使用DocumentClass类型创建文档,例如:

$doc = new-object tidy.documentclass
使用互操作程序集时,C#做了一些魔术,其中一个就是采用“Foo”的类规范,然后创建一个“FooClass”的实例。