NuGet.SharedPackageRepository.GetStoreDocument C# (CSharp) Method

GetStoreDocument() private method

private GetStoreDocument ( bool createIfNotExists = false ) : System.Xml.Linq.XDocument
createIfNotExists bool
return System.Xml.Linq.XDocument
        private XDocument GetStoreDocument(bool createIfNotExists = false)
        {
            try
            {
                // If the file exists then open and return it
                if (FileSystem.FileExists(StoreFilePath))
                {
                    using (Stream stream = FileSystem.OpenFile(StoreFilePath))
                    {
                        try
                        {
                            return XDocument.Load(stream);
                        }
                        catch (XmlException)
                        {
                            // There was an error reading the file, but don't throw as a result
                        }
                    }
                }

                // If it doesn't exist and we're creating a new file then return a
                // document with an empty packages node
                if (createIfNotExists)
                {
                    return new XDocument(new XElement("repositories"));
                }

                return null;
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                    String.Format(CultureInfo.CurrentCulture,
                                  NuGetResources.ErrorReadingFile,
                                  FileSystem.GetFullPath(StoreFilePath)), e);
            }
        }