![](/img/trans.png)
[英]Can I call an overloaded constructor from another constructor of the same class in C#?
[英]Is it possible to call an overloaded C# constructor from IronPython?
我正在尝试使用TextReader创建SessionState对象。 https://github.com/connamara/quickfixn/blob/master/QuickFIXn/SessionSettings.cs
public SessionSettings(string file){
}
public SessionSettings(TextReader conf)
{
}
我正在尝试调用第二个构造函数。 TextReader是一个抽象类,并且
>>> QuickFix.SessionSettings(System.IO.StringReader("BLAH"))
不起作用,也不会:
>>> QuickFix.SessionSettings.Overloads[System.IO.TextReader](System.IO.StringReader("BLAH"))
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'type' object has no attribute 'Overloads'
我可以通过子类化并实现__new__
和__init__
来调用它,但是有没有更好的方法不需要子类化每个多构造函数类型呢?
备查:
假定程序集A.dll引用B.dll,并且B.dll包含要子类化的目标类。
clr.AddReferenceToFile("A.dll") # loads b.dll behind the scenes
clr.AddReferenceToFile("B.dll")
现在,IronPython clr模块隐式具有对B.dll的两个引用,这可能会导致绝对的密码错误,例如上述错误。
解决方案似乎是只加载最小数量的dll,尽管我还没有看到太多有关这种情况发生的确切机制的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.