public bool Convert <TFrom, TTo>(TFrom fromItem, out TTo toItem) { toItem = default(TTo); if (fromItem is string) { var path = fromItem as string; var toType = typeof(TTo); if (toType.IsAssignableFrom(typeof(IDocument))) { if (Directory.Exists(path)) { // TODO: Handle directories return(false); } else { toItem = (TTo)DocumentFactory.CreateDocumentFromFile(path); if (toItem != null) { return(true); } } } } return(false); }
public static void Rename(this IDocument doc, string filename) { var path = Path.Combine(Path.GetDirectoryName(doc.LocalPath), filename); doc.SaveTo(path); var project = doc.Project; if (project != null) { project.Documents.Remove(doc); } File.Delete(doc.LocalPath); doc.Dispose(); if (project != null) { var document = DocumentFactory.CreateDocumentFromFile(path); project.Documents.Add(document); project.Save(); } }