Editor/TypeLibraryExtensions.cs
using Sandbox;
using Sandbox.Internal;
using System;
namespace ExtendedBox;
public static class TypeLibraryExtensions
{
public static SerializedProperty CreateProperty(this TypeLibrary typeLibrary, Type type, string title, Func<object> get, Action<object> set, Attribute[]? attributes = null, SerializedObject? parent = null)
{
return new ActionBasedSerializedProperty(type, title, title, "", get, set, attributes!, parent!)
{
PropertyToObject = typeLibrary.PropertyToObject
};
}
private static SerializedObject PropertyToObject(this TypeLibrary typeLibrary, SerializedProperty property)
{
TypeDescription type = typeLibrary.GetType(property.PropertyType);
if(type == null)
return null!;
Func<object> func = () => property.GetValue<object>();
if(func() == null)
return null!;
Type t = typeof(SerializedObject).Assembly.GetType("TypeSerializedObject")!;
return (SerializedObject)Activator.CreateInstance(t, func, type, property)!;
}
}