私は C# が初めてで、VB.NET アプリを変換しようとしています。このコードの使用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;
namespace TestXML
{
class Program
{
static void Main(string[] args)
{
XmlDataDocument Doc = new XmlDataDocument();
XmlNodeList nodeList;
XmlElement Element;
XmlNode node = null;
Doc.Load(@"UNC path of a doc.xml file");
Element = Doc.DocumentElement;
nodeList = Element.SelectNodes("Application");
foreach (XmlNode node in nodeList)
{
if (node.Attributes(@"Name").InnerText = @"Something")
break;
}
//gsCurrentMode is one of "Production","Test","Develope"
nodeList = node.SelectNodes("Instance");
foreach (XmlNode n in nodeList)
{
if (node.Attributes("Mode").Value = @"Production")
//if either of these two fails, Something shuts down
return node.Attributes("Server").InnerText;
else
{
return;
}
}
}
}
}
次のエラーが表示されます: 1. 「ノード」という名前のローカル変数をこのスコープで宣言することはできません。これは、「親または現在の」スコープで他の何かを示すために既に使用されている「ノード」に別の意味を与えるためです。これらのステートメントの場合: (nodeList の XmlNode ノード) 2. 非呼び出し可能メンバー 'System.Xml.XmlNode.Attributes' は、node.Attributes 行のメソッドのように使用できません。
元の VB.NET コードは次のとおりです。
Public Function GetProductionServer() As String
Dim Doc As New XmlDocument
Dim nodeList As XmlNodeList
Dim Element As XmlElement
Dim node As XmlNode = Nothing
Doc.Load("UNC Path to an Doc.xml")
Element = Doc.DocumentElement
nodeList = Element.SelectNodes("Application")
For Each node In nodeList
If node.Attributes("Name").InnerText = "Something" Then
Exit For
End If
Next
'--- gsCurrentMode is one of "Production","Test","Develope"
nodeList = node.SelectNodes("Instance")
For Each node In nodeList
If node.Attributes("Mode").Value = "Production" Then
'-- if either of these two fails, Something shuts down
Return node.Item("Server").InnerText
End If
Next
Return ""
End Function
誰かが私にいくつかのガイダンスを与えることができますか、事前に感謝します.