JD2022-TU1/main/tools/framework/JD.Serialization/uaf_partial/Actor.cs

105 lines
3 KiB
C#

using System;
using System.ComponentModel;
using System.Linq;
namespace JD.Serialization
{
public partial class Actor
{
public ActorComponent getComponent(Type type)
{
return COMPONENTS.FirstOrDefault(component => component.GetType() == type);
}
[Browsable(false)]
[TypeConverter(typeof(UAFObjectConverter))]
public Actor_Template Template { get; set; }
}
public partial class Actor_Template
{
public ActorComponent_Template getComponent(Type type)
{
return COMPONENTS.FirstOrDefault(component => component.GetType() == type);
}
public void Save(string filePath)
{
new LuaSerializer().SaveObjectToFile(this,filePath);
}
}
public class UAFDescriptionProvider : TypeDescriptionProvider
{
private ICustomTypeDescriptor td;
public UAFDescriptionProvider()
{
}
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
{
if (td == null)
{
td = base.GetTypeDescriptor(objectType, instance);
td = new UAFDescriptor(td);
}
return td;
}
}
public class UAFDescriptor : CustomTypeDescriptor
{
public UAFDescriptor(ICustomTypeDescriptor parent)
: base(parent)
{
}
public override PropertyDescriptorCollection GetProperties()
{
var cols = base.GetProperties();
return cols;
}
public override PropertyDescriptorCollection GetProperties(System.Attribute[] attributes)
{
var cols = base.GetProperties();
return cols;
}
}
public class SubPropertyDescriptor : PropertyDescriptor
{
private PropertyDescriptor _subPD;
private PropertyDescriptor _parentPD;
public SubPropertyDescriptor(PropertyDescriptor parentPD, PropertyDescriptor subPD, string pdname)
: base(pdname, null)
{
_subPD = subPD;
_parentPD = parentPD;
}
public override bool IsReadOnly
{
get { return false; }
}
public override void ResetValue(object component) { }
public override bool CanResetValue(object component) { return false; }
public override bool ShouldSerializeValue(object component)
{ return true; }
public override Type ComponentType { get { return _parentPD.ComponentType; } }
public override Type PropertyType { get { return _subPD.PropertyType; } }
public override object GetValue(object component)
{
return _subPD.GetValue(_parentPD.GetValue(component));
}
public override void SetValue(object component, object value)
{
_subPD.SetValue(_parentPD.GetValue(component), value);
OnValueChanged(component, EventArgs.Empty);
}
}
}