kopia lustrzana https://github.com/dl2alf/AirScout
31 wiersze
704 B
C#
31 wiersze
704 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.Text;
|
|
|
|
namespace ScoutBase.Core
|
|
{
|
|
public static class Cloning
|
|
{
|
|
public static T Clone<T>(this T source)
|
|
{
|
|
// Don't serialize a null object, simply return the default for that object
|
|
if (Object.ReferenceEquals(source, null))
|
|
{
|
|
return default(T);
|
|
}
|
|
|
|
IFormatter formatter = new BinaryFormatter();
|
|
using (MemoryStream stream = new MemoryStream())
|
|
{
|
|
formatter.Serialize(stream, source);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return (T)formatter.Deserialize(stream);
|
|
}
|
|
}
|
|
}
|
|
}
|