How will this example affect the using implementation in GetSite?
public abstract class SPSiteBase
{
protected abstract string Url { get; set; }
public abstract SPSite GetSite(string url = null);
}
public class SPSiteFactory : SPSiteBase
{
protected override sealed string Url { get; set; }
public override SPSite GetSite(string url = null)
{
using (SPSite site = new SPSite(string.IsNullOrEmpty(url) ? Url : url))
{
return site;
}
}
public SPSiteFactory() { }
public SPSiteFactory(string url)
{
Url = url;
}
}
I call it like this
SPSiteFactory siteFactory = new SPSiteFactory("http://portalurl/");
SPSite site = siteFactory.GetSite();
I've noticed that the code steps out of the using after I run the siteFactory.GetSite()
method but will the site
ever be disposed?
using { return }
is the same astry { return }
—it won't magically handle errors the calling code. Thususing
will dispose right away. – Dan Jan 3 '14 at 20:10