0

I want to check is object is empty or is NULL.

First I have a web method that take has input parameter XML document

[WebMethod(CacheDuration = 0, EnableSession=true, Description = "Učitaj dokument iz Aurore")]
public System.Xml.XmlDocument Load_DOK(System.Xml.XmlDocument XmlDoc)   //xml doc
{
}

In this method I have to check if XmlDoc is empty, if is throw error.

I wrote something like this:

try
{
    if( XmlDoc == null)
        errorMessage = "Input parameter is NULL!";
}
catch (Exception ex)
{
    WriteErrors.WriteToLogFile("WS.LOAD_DOK", ex.ToString());

    errorMessage = ex.Message;

    //Error exception
    soapEnvelop.LoadXml(@"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><soap:Body><Response_status>1</Response_status><Description>" + ex.Message + "</Description></soap:Body></soap:Envelope>");
    return soapEnvelop;
}

I want to know is this the right way or is there a simpler way to do it?

4

1 に答える 1

4

tryブロックは次のようになります

try 
{ 
    if( XmlDoc == null) 
    {
        throw new ArgumentNullException("XmlDoc");
    } 
    // carry on processing here.
}
于 2012-07-25T10:11:43.263 に答える