From a3729a11c7586466e9c610293e570c64a3390716 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 31 May 2013 20:10:51 +1200 Subject: [PATCH] Extract stream extensions to their own file. --- OpenRA.FileFormats/Exts.cs | 35 ------------ OpenRA.FileFormats/OpenRA.FileFormats.csproj | 1 + OpenRA.FileFormats/StreamExts.cs | 56 ++++++++++++++++++++ 3 files changed, 57 insertions(+), 35 deletions(-) create mode 100755 OpenRA.FileFormats/StreamExts.cs diff --git a/OpenRA.FileFormats/Exts.cs b/OpenRA.FileFormats/Exts.cs index f7e6c538aa..e58d62321c 100755 --- a/OpenRA.FileFormats/Exts.cs +++ b/OpenRA.FileFormats/Exts.cs @@ -41,41 +41,6 @@ namespace OpenRA return a.GetTypes().Select(t => t.Namespace).Distinct().Where(n => n != null); } - public static string ReadAllText(this Stream s) - { - using (s) - using (var sr = new StreamReader(s)) - return sr.ReadToEnd(); - } - - public static byte[] ReadAllBytes(this Stream s) - { - using (s) - { - var data = new byte[s.Length - s.Position]; - s.Read(data, 0, data.Length); - return data; - } - } - - public static void Write(this Stream s, byte[] data) - { - s.Write(data, 0, data.Length); - } - - public static IEnumerable ReadAllLines(this Stream s) - { - using (var sr = new StreamReader(s)) - for (; ; ) - { - var line = sr.ReadLine(); - if (line == null) - yield break; - else - yield return line; - } - } - public static bool HasAttribute(this MemberInfo mi) { return mi.GetCustomAttributes(typeof(T), true).Length != 0; diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index 57030eeb48..abe857a003 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -141,6 +141,7 @@ + diff --git a/OpenRA.FileFormats/StreamExts.cs b/OpenRA.FileFormats/StreamExts.cs new file mode 100755 index 0000000000..1d9c3bfe50 --- /dev/null +++ b/OpenRA.FileFormats/StreamExts.cs @@ -0,0 +1,56 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.IO; + +namespace OpenRA +{ + public static class StreamExts + { + public static string ReadAllText(this Stream s) + { + using (s) + using (var sr = new StreamReader(s)) + return sr.ReadToEnd(); + } + + public static byte[] ReadAllBytes(this Stream s) + { + using (s) + { + var data = new byte[s.Length - s.Position]; + s.Read(data, 0, data.Length); + return data; + } + } + + public static void Write(this Stream s, byte[] data) + { + s.Write(data, 0, data.Length); + } + + public static IEnumerable ReadAllLines(this Stream s) + { + using (var sr = new StreamReader(s)) + { + for (;;) + { + var line = sr.ReadLine(); + if (line == null) + yield break; + else + yield return line; + } + } + } + } +}