gpt4 book ai didi

javascript - COM->.NET - 无法访问重载方法

转载 作者:行者123 更新时间:2023-11-30 07:46:01 26 4
gpt4 key购买 nike

我正在尝试访问 .Net 库 (The Image Resizer)来自 COM (jscript)。

我已经在相关类上尝试了 IDispatch 和类接口(interface)生成,以及 [ClassInterface( ClassInterfaceType.AutoDual)]。

有一个方法有 3 个重载:

Bitmap Build(object, ResizeSettings settings)
void Build(object source, object dest, string settings)
void Build(object source, object dest, ResizeSettings settings)

打电话

Build("file",s); //works

以下都生成“参数数量错误或属性分配无效”(JScript 运行时错误)

Build("file","file", s) 
Build("file","file","settings

我找不到任何理由说明重载不应通过互操作工作,尤其是当 arg 计数不同时。我错过了什么吗?

更新:这里是方法定义的完整代码。第二个过载是不可访问的。不仅仅是这些方法——在每个重载方法中,我似乎只能访问第一个重载。这是未记录的 COM 错误/设计缺陷吗?

    /// <summary>
/// Provides methods for generating resized images, and for reading and writing them to disk.
/// Use ImageBuilder.Current to get the current instance (as configured in the application configuration), or use ImageBuilder.Current.Create() to control which extensions are used.
/// </summary>
public class ImageBuilder : AbstractImageProcessor, IQuerystringPlugin
{


/// <summary>
/// Resizes and processes the specified source image and returns a bitmap of the result.
/// This method assumes that transparency will be supported in the final output format, and therefore does not apply a matte color. Use &amp;bgcolor to specify a background color
/// if you use this method with a non-transparent format such as Jpeg.
/// </summary>
/// <param name="source">May be an instance of string (a physical path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream.</param>
/// <param name="settings">Resizing and processing command to apply to the.</param>
public virtual Bitmap Build(object source, ResizeSettings settings) {
BitmapHolder bh = new BitmapHolder();
Build(source, bh, settings);
return bh.bitmap;
}

/// <summary>
/// Resizes and processes the specified source image and stores the encoded result in the specified destination.
/// </summary>
/// <param name="source">May be an instance of string (a physical path or app-relative virtual path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. app-relative virtual paths will use the VirtualPathProvider system</param>
/// <param name="dest">May be a physical path (string), or a Stream instance. Does not have to be seekable.</param>
/// <param name="settings">Resizing and processing command to apply to the.</param>
public virtual void Build(object source, object dest, ResizeSettings settings) {
ResizeSettings s = new ResizeSettings(settings);

最佳答案

没错,COM 不会“执行”方法重载。

但是。见http://msdn.microsoft.com/en-us/library/ms182197(v=vs.80).aspx .

这是静态分析工具 FxCop 上的文档页面。但是那里有一些信息,对 COM 开发人员很有用:

When overloaded methods are exposed to COM clients, only the first method overload retains its name. Subsequent overloads are uniquely renamed by appending to the name an underscore character '_' and an integer that corresponds to the order of declaration of the overload.

另见
Overloads in COM interop (CCW) - IDispatch names include suffix (_2, _3, etc)

因此,通过 COM 层,您可以使用

调用您的原始方法
Build_2("file", "file", s);
Build_3("file", "file", settings);

关于javascript - COM->.NET - 无法访问重载方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6031668/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com