我正在尝试使用python创建单例类的实例。该类如下所示:
public sealed class Test
{
private Test()
{
}
public static Test GetInstance()
{
.......
}
}
我已经尝试过这里的所有内容:
如何在python中创建此类的实例?
我找到了解决方法。
#set reference
ref = clr.AddReference(r'Assemblypath')
#get type
testType= ref.GetType('Namespace.Test')
#GetUninitializedObject
testUninitialize=System.Runtime.Serialization.FormatterServices.GetUninitializedObject(testType);
#Now it's possible to call the method
test = testUninitialize.GetInstance()