In my extremely simplified code sample my Foo() method calls GetXmlDataSource()
which returns an XmlDataSource
. CA2000 says that I should Dispose()
an XmlDatasource before losing scope.
- Should I wrap each
XmlDataSource
in a using statement? - Should I use
try
/catch
/finally
in the lower one and ausing
in the upper one? - Do I effectively have two
XmlDataSource
objects, one in the upper method and one in the lower method?
I'm a little fuzzy on language behavior in this one and I want to be a good boy.
void Foo()
{
XmlDataSource xds = GetXmlDataSource();
}
XmlDataSource GetXmlDataSource()
{
XmlDataSource xmlDataSource = new XmlDataSource();
return xmlDataSource;
}