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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user