我有以下代码是在使用telerik代码转换器将一段遗留代码转换为C#后创建的,但它产生了错误
错误473成员' System.Xml.XmlWriter.Create(System.IO.Stream,System.Xml.XmlWriterSettings)'无法使用实例引用访问;使用类型名称对其进行限定
public virtual string Serialize()
{
System.IO.StreamReader streamReader = null;
System.IO.MemoryStream memoryStream = null;
try
{
memoryStream = new System.IO.MemoryStream();
System.Xml.XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings();
xmlWriterSettings.Indent = false;
System.Xml.XmlWriter xmlWriter = xmlWriter.Create(memoryStream, xmlWriterSettings);
Serializer.Serialize(xmlWriter, this);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
streamReader = new System.IO.StreamReader(memoryStream);
return streamReader.ReadToEnd();
}
finally
{
if ((((streamReader) != null)))
{
streamReader.Dispose();
}
if ((((memoryStream) != null)))
{
memoryStream.Dispose();
}
}
}
错误发生在该行:
System.Xml.XmlWriter xmlWriter = xmlWriter.Create(memoryStream, xmlWriterSettings);
在VB.Net中,代码如下:
Public Overridable Function Serialize() As String
Dim streamReader As System.IO.StreamReader = Nothing
Dim memoryStream As System.IO.MemoryStream = Nothing
Try
memoryStream = New System.IO.MemoryStream()
Dim xmlWriterSettings As System.Xml.XmlWriterSettings = New System.Xml.XmlWriterSettings()
xmlWriterSettings.Indent = False
Dim xmlWriter As System.Xml.XmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings)
Serializer.Serialize(xmlWriter, Me)
memoryStream.Seek(0, System.IO.SeekOrigin.Begin)
streamReader = New System.IO.StreamReader(memoryStream)
Return streamReader.ReadToEnd
Finally
If (Not (streamReader) Is Nothing) Then
streamReader.Dispose()
End If
If (Not (memoryStream) Is Nothing) Then
memoryStream.Dispose()
End If
End Try
End Function