Make userdata fields/properties/methods case insensitive

While this can potentially cause collisions, this allows us to easily use Lua's style guide
This commit is contained in:
2018-11-20 14:17:15 +01:00
parent df8c7b99c9
commit 8f6d2591f3
2 changed files with 9 additions and 8 deletions

View File

@@ -9,9 +9,9 @@ namespace Upsilon.BaseTypes.UserData
public UserDataType(System.Type type)
{
Type = type;
Variables = type.GetFields().ToDictionary(x => x.Name, x => x);
Properties = type.GetProperties().ToDictionary(x => x.Name, x => x);
Methods = type.GetMethods().ToDictionary(x => x.Name, x => x);
Variables = type.GetFields().ToDictionary(x => x.Name.ToLowerInvariant(), x => x);
Properties = type.GetProperties().ToDictionary(x => x.Name.ToLowerInvariant(), x => x);
Methods = type.GetMethods().ToDictionary(x => x.Name.ToLowerInvariant(), x => x);
}
private System.Type Type { get; }
@@ -23,6 +23,7 @@ namespace Upsilon.BaseTypes.UserData
{
if (value.GetType() != Type)
return null;
member = member.ToLowerInvariant();
if (Variables.TryGetValue(member, out var info))
{
return info.GetValue(value).ToLuaType();
@@ -41,6 +42,7 @@ namespace Upsilon.BaseTypes.UserData
public void Set(object value, string member, LuaType newValue)
{
member = member.ToLowerInvariant();
if (value.GetType() != Type)
return;
if (Variables.TryGetValue(member, out var info))
@@ -51,7 +53,6 @@ namespace Upsilon.BaseTypes.UserData
{
property.SetValue(value, newValue.ToCSharpObject());
}
return;
}
}
}