Question : How to convert this VB.NET code to VC# code?

           Private Sub ReadConfig(ByRef s As System.Web.HttpServerUtility)
                  Dim XMLString As String = FileUtility.ReadFile(s.MapPath(CONFIG_PATH))
                  Dim doc As New XmlDocument
                  Try
                        doc.LoadXml(XMLString)
                  Catch ex As Exception
                        Exit Sub
                  End Try
                  
                  Hardwares = New List(Of CHardware)
                  Dim nlHardwares As XmlNodeList
                  nlHardwares = doc.SelectNodes("/Hardwares/Hardware")
                  For Each eleHardware As XmlElement In nlHardwares
                        Hardwares.Add(ParseHardwareNode(eleHardware))
                  Next
            End Sub

            Private Function ParseHardwareNode(ByVal eleHardware As XmlElement) As CHardware
                  Dim oHardware As CHardware = New CHardware()
                  oHardware.HardwareType = eleHardware.GetAttribute("HardwareType")

                  Dim eleHtmlMetaInfo As XmlElement = eleHardware.SelectSingleNode("./HtmlMetaInfo")
                  If eleHtmlMetaInfo IsNot Nothing Then
                        oHardware.HtmlMetaInfo = eleHtmlMetaInfo.InnerText
                  End If

                  Dim nlIdentities As XmlNodeList = eleHardware.SelectNodes("./Serial")
                  For Each eleSerial As XmlElement In nlIdentities
                        Dim oHardwareSerial As CHardware.CHardwareSerial = New CHardware.CHardwareSerial()
                        Dim nlHeaders As XmlNodeList = eleSerial.SelectNodes("./Header")
                        For Each eleHeader As XmlElement In nlHeaders
                              Dim oHardwareSerialArea As CHardware.CHardwareSerial.CHardwareSerialArea = New CHardware.CHardwareSerial.CHardwareSerialArea(eleHeader.GetAttribute("Area"), eleHeader.GetAttribute("Scope"))
                              oHardwareSerial.Areas.Add(oHardwareSerialArea)
                        Next
                        oHardware.HardwareIdentities.Add(oHardwareSerial)
                  Next

                  Dim nlSubHardwares As XmlNodeList = eleHardware.SelectNodes("./Hardware")
                  For Each eleSubHardware As XmlElement In nlSubHardwares
                        Dim oSubHardware As CHardware = ParseHardwareNode(eleSubHardware)
                        oSubHardware.ParentHardware = oHardware
                        oHardware.SubHardwares.Add(oSubHardware)
                  Next
                  
                  Return oHardware
            End Function

            Private Function SearchMatchingHardware(ByRef Request As System.Web.HttpRequest, ByVal oHardware As CHardware) As CHardware
                  If oHardware.IsMatch(Request) = True Then
                        If oHardware.SubHardwares.Count > 0 Then
                              For Each oSubHardware As CHardware In oHardware.SubHardwares
                                    Dim oMatchedSubHardware As CHardware = SearchMatchingHardware(Request, oSubHardware)
                                    If oMatchedSubHardware IsNot Nothing Then
                                          Return oMatchedSubHardware
                                    End If
                              Next
                        End If

                        Return oHardware
                  Else
                        Return Nothing
                  End If
            End Function

            Public Function DetectHardwareInfo(ByRef Request As System.Web.HttpRequest, ByRef HtmlMetaInfo As String) As String
                  HtmlMetaInfo = Nothing
                  For Each oHardware As CHardware In Me.Hardwares
                        Dim oMatchedHardware As CHardware = SearchMatchingHardware(Request, oHardware)
                        If oMatchedHardware IsNot Nothing Then
                              HtmlMetaInfo = oMatchedHardware.HtmlMetaInfo
                              Return oMatchedHardware.HardwareType
                        End If
                  Next
                  Return Nothing
            End Function

Answer : How to convert this VB.NET code to VC# code?

here:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
private void ReadConfig(ref System.Web.HttpServerUtility s)
{
    string XMLString = FileUtility.ReadFile(s.MapPath(CONFIG_PATH));
    XmlDocument doc = new XmlDocument();
    try {
        doc.LoadXml(XMLString);
    }
    catch (Exception ex) {
        return;
    }
    
    Hardwares = new List();
    XmlNodeList nlHardwares = default(XmlNodeList);
    nlHardwares = doc.SelectNodes("/Hardwares/Hardware");
    foreach (XmlElement eleHardware in nlHardwares) {
        Hardwares.Add(ParseHardwareNode(eleHardware));
    }
}
 
private CHardware ParseHardwareNode(XmlElement eleHardware)
{
    CHardware oHardware = new CHardware();
    oHardware.HardwareType = eleHardware.GetAttribute("HardwareType");
    
    XmlElement eleHtmlMetaInfo = eleHardware.SelectSingleNode("./HtmlMetaInfo");
    if (eleHtmlMetaInfo != null) {
        oHardware.HtmlMetaInfo = eleHtmlMetaInfo.InnerText;
    }
    
    XmlNodeList nlIdentities = eleHardware.SelectNodes("./Serial");
    foreach (XmlElement eleSerial in nlIdentities) {
        CHardware.CHardwareSerial oHardwareSerial = new CHardware.CHardwareSerial();
        XmlNodeList nlHeaders = eleSerial.SelectNodes("./Header");
        foreach (XmlElement eleHeader in nlHeaders) {
            CHardware.CHardwareSerial.CHardwareSerialArea oHardwareSerialArea = new CHardware.CHardwareSerial.CHardwareSerialArea(eleHeader.GetAttribute("Area"), eleHeader.GetAttribute("Scope"));
            oHardwareSerial.Areas.Add(oHardwareSerialArea);
        }
        oHardware.HardwareIdentities.Add(oHardwareSerial);
    }
    
    XmlNodeList nlSubHardwares = eleHardware.SelectNodes("./Hardware");
    foreach (XmlElement eleSubHardware in nlSubHardwares) {
        CHardware oSubHardware = ParseHardwareNode(eleSubHardware);
        oSubHardware.ParentHardware = oHardware;
        oHardware.SubHardwares.Add(oSubHardware);
    }
    
    return oHardware;
}
 
private CHardware SearchMatchingHardware(ref System.Web.HttpRequest Request, CHardware oHardware)
{
    if (oHardware.IsMatch(Request) == true) {
        if (oHardware.SubHardwares.Count > 0) {
            foreach (CHardware oSubHardware in oHardware.SubHardwares) {
                CHardware oMatchedSubHardware = SearchMatchingHardware(Request, oSubHardware);
                if (oMatchedSubHardware != null) {
                    return oMatchedSubHardware;
                }
            }
        }
        
        return oHardware;
    }
    else {
        return null;
    }
}
 
public string DetectHardwareInfo(ref System.Web.HttpRequest Request, ref string HtmlMetaInfo)
{
    HtmlMetaInfo = null;
    foreach (CHardware oHardware in this.Hardwares) {
        CHardware oMatchedHardware = SearchMatchingHardware(Request, oHardware);
        if (oMatchedHardware != null) {
            HtmlMetaInfo = oMatchedHardware.HtmlMetaInfo;
            return oMatchedHardware.HardwareType;
        }
    }
    return null;
}
Random Solutions  
 
programming4us programming4us