using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using SharpGLTF.IO;
using SharpGLTF.Schema2;
namespace SharpGLTF.Reflection
{
///
/// Extends with reflection APIs
///
///
/// Typically, most objects found in glTF schemas are either enums or classes that inherit
/// from class, but that's not always the case. In these cases
/// the base class should be to support all features.
///
public abstract class JsonReflectable : JsonSerializable, IReflectionObject
{
#region reflection
public const string SCHEMANAME = "Object";
protected override string GetSchemaName() => SCHEMANAME;
protected virtual IEnumerable ReflectFieldsNames()
{
return Enumerable.Empty();
}
protected virtual bool TryReflectField(string name, out FieldInfo value)
{
value = default;
return false;
}
IEnumerable IReflectionObject.GetFields()
{
foreach (var name in ReflectFieldsNames())
{
if (TryReflectField(name, out var finfo)) yield return finfo;
}
}
bool IReflectionObject.TryGetField(string name, out FieldInfo value)
{
return TryReflectField(name, out value);
}
#endregion
#region serialization
protected override void SerializeProperties(Utf8JsonWriter writer)
{
}
protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader)
{
reader.Skip();
}
#endregion
}
}