我有一个 .NET COM 对象,用于从 C 代码调用。
[EventTrackingEnabled(true)]
[ComVisible(true)]
public class ComObject : IComObject
{
private static XslCompiledTransform transformer = null;
private static string transformerXsltPath = null;
private static string TransformerXsltPath
{
get
{
return transformerXsltPath;
}
set
{
transformerXsltPath = value;
}
}
private static XslCompiledTransform Transformer
{
get
{
return transformer;
}
set
{
transformer = value;
}
}
[ComVisible(true)]
public bool TransformXML(String inputPath, String xsltPath, String outputPath)
{
// ....
if (Transformer == null || xsltPath != TransformerXsltPath)
{
Transformer = new XslCompiledTransform(true);
Transformer.Load(xsltPath, new XsltSettings(true, true), new XmlUrlResolver());
}
// ...
}
}
我想保持 com 对象的状态,只要我调用这个方法。由静态成员。所以当我再次调用它时,状态成员将被初始化。
但问题是,只有Transformer
对象在第二次调用中保持初始化,但transformerXsltPath
字符串重新启动为 null。
怎么可能?