Bug fixes and improvements.

- Fixed an issue pertaining to implicit value casting in the property
reflection.
- Removed some unnecessary generated whitespace in the class data.
- Added some missing properties to the generated class data.
- Moved the Quaternion type into the DataTypes namespace.
This commit is contained in:
CloneTrooper1019
2019-07-03 09:48:05 -05:00
parent de8df15d3f
commit 4e1fdc0a22
9 changed files with 75 additions and 22 deletions

View File

@ -21,7 +21,7 @@ namespace RobloxFiles
/// <summary>The ClassName of this Instance.</summary>
public string ClassName => GetType().Name;
/// <summary>Internal list of Properties that are under this Instance.</summary>
/// <summary>Internal list of properties that are under this Instance.</summary>
private Dictionary<string, Property> props = new Dictionary<string, Property>();
/// <summary>A list of properties that are defined under this Instance.</summary>
@ -30,7 +30,7 @@ namespace RobloxFiles
/// <summary>The raw list of children for this Instance.</summary>
internal List<Instance> Children = new List<Instance>();
/// <summary>Raw value of the Instance's parent.</summary>
/// <summary>The raw value of the Instance's parent.</summary>
private Instance RawParent;
/// <summary>The name of this Instance.</summary>

View File

@ -6,7 +6,6 @@ using RobloxFiles.BinaryFormat;
using RobloxFiles.BinaryFormat.Chunks;
using RobloxFiles.DataTypes;
using RobloxFiles.Utility;
namespace RobloxFiles
{
@ -140,6 +139,12 @@ namespace RobloxFiles
}
}
if (Name.Contains(" "))
{
var implicitName = Name.Replace(' ', '_');
return implicitName;
}
return Name;
}
}
@ -188,13 +193,42 @@ namespace RobloxFiles
FieldInfo field = Instance.GetType()
.GetField(ImplicitName, BindingFlags);
try
if (field != null)
{
field?.SetValue(Instance, value);
}
catch
{
Console.WriteLine($"RobloxFiles.Property - Failed to cast value {value} into property {Instance.ClassName}.{Name}");
Type fieldType = field.FieldType;
Type valueType = value?.GetType();
if (fieldType == valueType || value == null)
{
try
{
field.SetValue(Instance, value);
}
catch
{
Console.WriteLine($"RobloxFiles.Property - Failed to cast value {value} into property {Instance.ClassName}.{Name}");
}
}
else if (valueType != null)
{
var typeWrapper = new Type[] { valueType };
MethodInfo implicitCast = fieldType.GetMethod("op_Implicit", typeWrapper);
if (implicitCast != null)
{
var valueWrapper = new object[] { value };
try
{
object castedValue = implicitCast.Invoke(null, valueWrapper);
field.SetValue(Instance, castedValue);
}
catch
{
Console.WriteLine($"RobloxFiles.Property - Failed to implicitly cast value {value} into property {Instance.ClassName}.{Name}");
}
}
}
}
}
}