我正在为Visio开发VSTO加载项,并且需要使用Document.SolutionXmlElement属性保存文档属性。以下代码演示了处理程序,该处理程序在保存之前将对象的XML序列化。基于阅读,我将C#类实例包装在具有名称属性的SolutionXml包装器中,该属性设置为封闭的序列化类实例的元素名称:
margin: 30px auto;
serializzed XML如下:
private void Document_Saved(Visio.Document document)
{
IDictionary<string,ModelGenmVCModel> documentModel = GetRibbon().documentModel;
if (documentModel.TryGetvalue(document.Name,out ModelGenmVCModel modelGenmVCModel))
{
try
{
string serializedmodel = new SolutionXml(modelGenmVCModel,ModelGenVisioAddIn.Properties.Resources.SolutionXmlElementName).Serialize();
LOGGER.Debug(String.Format("Saving model gen properties:\n{0}",serializedmodel));
document.SolutionXMLElement[ModelGenVisioAddIn.Properties.Resources.SolutionXmlElementName] = serializedmodel;
} catch ( Exception e)
{
LOGGER.Error(String.Format("Serialization error {0}\n{1}",e.Message,e.StackTrace));
}
}
}
但是,我抛出了“无效参数”异常。任何帮助将不胜感激。
感谢和问候 安德鲁