26 lines
781 B
C#
26 lines
781 B
C#
using System;
|
|
using System.Linq;
|
|
|
|
namespace JD.Serialization
|
|
{
|
|
public static class CloneExtensions
|
|
{
|
|
public static T Clone<T>(this T source)
|
|
where T : SpecialCustomTypeDescriptor, new()
|
|
{
|
|
var clone = (T)Activator.CreateInstance(source.GetType());
|
|
source.CopyTo(clone);
|
|
return clone;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copies all the matching properties in the target.
|
|
/// </summary>
|
|
public static void CopyTo(this SpecialCustomTypeDescriptor source, SpecialCustomTypeDescriptor target)
|
|
{
|
|
var serializer = new LuaSerializer();
|
|
string luaString = serializer.Serialize(source);
|
|
serializer.Deserialize(luaString, target);
|
|
}
|
|
}
|
|
}
|