[longomatch/redesign: 110/120] Add objects cloner
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch/redesign: 110/120] Add objects cloner
- Date: Sat, 9 Apr 2011 18:07:55 +0000 (UTC)
commit dc71b1ed68c1ca79214ca18c0a9b30f228aa4404
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Sat Apr 9 16:42:34 2011 +0200
Add objects cloner
LongoMatch/Common/Cloner.cs | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch/Common/Cloner.cs b/LongoMatch/Common/Cloner.cs
new file mode 100644
index 0000000..7b00c09
--- /dev/null
+++ b/LongoMatch/Common/Cloner.cs
@@ -0,0 +1,40 @@
+//
+// Copyright (C) 2011 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.IO;
+
+using LongoMatch.Common;
+
+namespace LongoMatch.Common
+{
+ public static class Cloner
+ {
+ public static T Clone<T> (this T source) {
+ if (Object.ReferenceEquals(source, null))
+ return default(T);
+
+ Stream s = new MemoryStream();
+ using (s) {
+ SerializableObject.Save<T>(source, s);
+ s.Seek(0, SeekOrigin.Begin);
+ return SerializableObject.Load<T>(s);
+ }
+ }
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]