From 0bde8601602e72acb32595ca2912b54844020803 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Fri, 5 Feb 2016 15:08:00 -0500 Subject: [PATCH] Add convenience method to get an ObjectModel directly from a File --- .../ObjectModels/FileSystem/File.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/FileSystem/File.cs b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/FileSystem/File.cs index 105b5efc..8aa1e69f 100644 --- a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/FileSystem/File.cs +++ b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/FileSystem/File.cs @@ -168,6 +168,23 @@ namespace UniversalEditor.ObjectModels.FileSystem return clone; } + /// + /// Gets an for this file using the specified . + /// + /// The type of to return. + /// The specifying how to read the file data. + /// An with the file data, or null if the specified ObjectModel cannot be retrieved with the specified DataFormat from this file. + public T GetObjectModel(DataFormat df) where T : ObjectModel, new() + { + byte[] data = GetData(); + MemoryAccessor ma = new MemoryAccessor(data); + + T om = new T(); + Document.Load(om, df, ma); + + return om; + } + public override string ToString() { string strSize = "*";