【发布时间】:2014-09-04 01:26:46
【问题描述】:
我正在创建一个 COM 可见的 dll,并试图重载一个方法。
所以基本上这段代码:
[ComVisible(true)]
[ProgId("TAF.TextLog")]
[Guid("af3f89ed-4732-4367-a222-2a95b8b75659")]
public class TextLog
{
String _logFilePath;
public TextLog()
{
}
[ComVisible(true)]
public void Create(string filePath)
{
String path = Path.GetDirectoryName(filePath);
if (Directory.Exists(path))
{
_logFilePath = filePath;
}
[ComVisible(true)]
public void Write(string message)
{
WriteMessage(null, message, AlertMsg.MsgTypes.Info);
}
[ComVisible(true)]
public void Write(string title, string message, AlertMsg.MsgTypes messageType)
{
WriteMessage(title, message, messageType);
}
private void WriteMessage(string title, string message, AlertMsg.MsgTypes messageType)
{
using (StreamWriter file = new StreamWriter(_logFilePath, true))
{
if (title == null)
file.WriteLine(String.Format("{0:yyyy-MM-dd HH:mm:ss}\t{1}", DateTime.Now, message));
else
file.WriteLine(String.Format("{0:yyyy-MM-dd HH:mm:ss}\t{1}\t{2}\t{3}", DateTime.Now, title, message, messageType));
}
}
}
看起来这是不可能的。如果我从调用程序调用 .Write(顺便说一句,这是一个非常简单的 VBSCript),我会收到一个错误,表明我的参数不正确。
这是调用VBscript的代码:
Set myObj = CreateObject("TAF.TextLog")
myObj.Create("C:\temp\textlog.txt")
myObj.Write "title", "test message 1", 1
如果我在 dll 中只有一个 .Write 方法,它可以正常工作。有人可以告诉我这样的重载是否可以在 dll 中实现?
【问题讨论】:
标签: c# dll vbscript overloading