public static T GetXaml <T>(string path) { using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path)) { return((T)XamlConfigurationParser.LoadFrom(stream)); } }
private static UIElement Read(string path) { using (var stream = File.OpenRead(path)) { Throws.IfNot(stream != null, "The requested file is not exist."); // создаем экземпляр return((UIElement)XamlConfigurationParser.LoadFrom(stream)); } }
protected virtual T GetOrAdd <T>(string key, Func <T> func) { var paths = new List <string>() { Path.Combine(DataDirectory, key) }; if (ArchiveFiles) { paths.Insert(0, Path.Combine(DataDirectory, $"{key}.zip")); } foreach (var path in paths) { if (File.Exists(path)) { if (path.EndsWith("zip")) { using (var archive = ZipFile.OpenRead(path)) { var entry = archive.Entries.FirstOrDefault(); using (var stream = entry.Open()) { return((T)XamlConfigurationParser.LoadFrom(stream)); } } } else { return((T)XamlConfigurationParser.LoadFrom(path)); } } } var data = func(); if (data != null) { var path = paths[0]; if (path.EndsWith("zip")) { using (var memoryStream = File.Create(path)) { using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create)) { var entry = archive.CreateEntry(key); using (var stream = entry.Open()) { XamlConfigurationParser.SaveTo(stream, data); } } } } } return(data); }
protected T GetXaml <T>(string path) { using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(path)) { Throws.IfNot(stream != null, "The requested file is not found in embedded resource."); // создаем экземпляр return((T)XamlConfigurationParser.LoadFrom(stream)); } }
public Task <Article> Read(Stream stream) { return(Task.Run <Article>(() => (Article)XamlConfigurationParser.LoadFrom(stream))); }
public Task <Content> Read(Stream stream) { return(Task.Run <Content>(() => (Content)XamlConfigurationParser.LoadFrom(stream))); }