in Samples-NetCore/DotNetPad/DotNetPad.Applications/Controllers/FileController.cs [246:286]
private DocumentFile OpenCore(string fileName = null, bool setActiveDocument = true)
{
if (string.IsNullOrEmpty(fileName))
{
var result = fileDialogService.ShowOpenFileDialog(shellService.ShellView, allFilesType);
if (result.IsValid)
{
fileName = result.FileName;
}
}
if (string.IsNullOrEmpty(fileName))
{
return null;
}
// Check if document is already opened
var document = fileService.DocumentFiles.SingleOrDefault(d => d.FileName == fileName);
if (document == null)
{
string fileExtension = Path.GetExtension(fileName);
if (!new[] { ".cs", ".vb" }.Contains(fileExtension))
{
Trace.TraceError(string.Format(CultureInfo.InvariantCulture,
"The extension of the file '{0}' is not supported.", fileName));
messageService.ShowError(shellService.ShellView, string.Format(CultureInfo.CurrentCulture, Resources.OpenFileUnsupportedExtension, fileName));
return null;
}
var documentType = fileExtension == ".cs" ? DocumentType.CSharp : DocumentType.VisualBasic;
document = new DocumentFile(documentType, LoadDocumentContent)
{
FileName = fileName
};
fileService.AddDocument(document);
}
if (setActiveDocument) { ActiveDocumentFile = document; }
return document;
}