//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Runtime.CompilerServices;
using System.Text;
namespace BansheeEngine
{
/** @addtogroup Serialization
* @{
*/
#pragma warning disable 649
///
/// Allows you to access meta-data about a managed object and its fields. Similar to Reflection but simpler and faster.
///
public sealed class SerializableObject : ScriptObject
{
internal SerializableProperty parentProperty;
internal object parentObject;
private SerializableField[] _fields;
private Type type;
///
/// Type of the underlying object.
///
public Type Type { get { return type; } }
///
/// Underlying object instance, if any.
///
public object Object { get { return parentObject; } }
///
/// Creates a new serializable object for the specified object type.
///
/// C# type of the object.
/// Property used for retrieving this entry.
public SerializableObject(Type objectType, SerializableProperty parentProperty)
{
Internal_CreateInstance(this, objectType);
this.parentProperty = parentProperty;
this.parentObject = null;
this.type = objectType;
}
///
/// Creates a new serializable object for the specified object type.
///
/// C# type of the object.
/// Specific instance of the object of .
public SerializableObject(Type objectType, object parentObject)
{
Internal_CreateInstance(this, objectType);
this.parentProperty = null;
this.parentObject = parentObject;
this.type = objectType;
}
///
/// Creates a new serializable object for the specified object. Object must not be null.
///
/// Specific instance of the object.
public SerializableObject(object parentObject)
{
Internal_CreateInstance(this, parentObject.GetType());
this.parentProperty = null;
this.parentObject = parentObject;
this.type = parentObject.GetType();
}
///
/// Returns all fields in the object.
///
public SerializableField[] Fields
{
get { return _fields; }
}
///
/// Returns the specific object instance this object is operating on.
///
/// Object instance.
public object GetReferencedObject()
{
if (parentProperty != null)
return parentProperty.GetValue