[longomatch/redesign3: 108/143] Add objects cloner



commit 322b93b52f2d5965eb0907fef3649496b5a0f401
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]