/// <summary>
        ///     Parses the resource into a strongly-typed object.
        /// </summary>
        /// <typeparam name="TData">The type of the data object to deserialise the ProtoContract file into.</typeparam>
        /// <param name="fileName">Name of the file to parse.</param>
        /// <returns>An instance of <see cref="TData" />, populated with deserialised data from the ProtoContract file.</returns>
        public static TData ParseBinaryResourceAs <TData>(string fileName) where TData : class
        {
            var assembly = typeof(TData).Assembly;
            var stream   = GetResourceStream(assembly, fileName);

            using var reader = new BinaryReader(stream);
            return(ProtoEx.Deserialise <TData>(reader.ReadBytes((int)stream.Length)));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Deserialises the specified file as a strongly-typed object.
        /// </summary>
        /// <typeparam name="TModel">The type of object to deserialise into.</typeparam>
        public TModel ParseAsProtoObject <TModel>() where TModel : class, new()
        {
            var bytes = _fileOnDisk.Exists ? File.ReadAllBytes(_fileOnDisk.FullName) : new byte[] { };

            return(ProtoEx.Deserialise <TModel>(bytes));
        }