| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- using System;
- using System.Runtime.CompilerServices;
- namespace BansheeEngine
- {
- /** @addtogroup Serialization
- * @{
- */
- /// <summary>
- /// Provides utility methods dealing with object serialization.
- /// </summary>
- public static class SerializableUtility
- {
- /// <summary>
- /// Clones the specified object. Non-serializable types and fields are ignored in clone. A deep copy is performed
- /// on all serializable elements except for resources or game objects.
- /// </summary>
- /// <param name="original">Non-null reference to the object to clone. Object type must be serializable.</param>
- /// <returns>Deep copy of the original object.</returns>
- public static object Clone(object original)
- {
- return Internal_Clone(original);
- }
- /// <summary>
- /// Creates an empty instance of the specified type.
- /// </summary>
- /// <typeparam name="T">Type of the object to create. Must be serializable.</typeparam>
- /// <returns>New instance of the specified type, or null if the type is not serializable.</returns>
- public static T Create<T>()
- {
- return (T)Internal_Create(typeof(T));
- }
- /// <summary>
- /// Creates an empty instance of the specified type.
- /// </summary>
- /// <param name="type">Type of the object to create. Must be serializable.</param>
- /// <returns>New instance of the specified type, or null if the type is not serializable.</returns>
- public static object Create(Type type)
- {
- return Internal_Create(type);
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern object Internal_Clone(object original);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern object Internal_Create(Type type);
- }
- /** @} */
- }
|