diff --git a/Assets/XLua/Src/CodeEmit.cs b/Assets/XLua/Src/CodeEmit.cs index 59ee770b5..4ffed4c21 100644 --- a/Assets/XLua/Src/CodeEmit.cs +++ b/Assets/XLua/Src/CodeEmit.cs @@ -1257,7 +1257,7 @@ public Type EmitTypeWrap(Type toBeWrap) .Where(m => !m.IsSpecialName || ( ((m.Name == "get_Item" && m.GetParameters().Length == 1) || (m.Name == "set_Item" && m.GetParameters().Length == 2)) - && m.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) + && m.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) && toBeWrap.GetCustomAttribute() == null ) ).GroupBy(m => m.Name).ToList(); var supportOperators = toBeWrap.GetMethods(staticFlag) @@ -1293,7 +1293,7 @@ public Type EmitTypeWrap(Type toBeWrap) { if (prop.GetIndexParameters().Length > 0) { - if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string))) + if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) || toBeWrap.GetCustomAttribute() != null) { itemGetter.Add(getter); } @@ -1309,7 +1309,7 @@ public Type EmitTypeWrap(Type toBeWrap) { if (prop.GetIndexParameters().Length > 0) { - if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string))) + if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) || toBeWrap.GetCustomAttribute() != null) { itemSetter.Add(setter); } diff --git a/Assets/XLua/Src/Editor/Generator.cs b/Assets/XLua/Src/Editor/Generator.cs index adc0766ac..39869f363 100644 --- a/Assets/XLua/Src/Editor/Generator.cs +++ b/Assets/XLua/Src/Editor/Generator.cs @@ -309,7 +309,7 @@ static void getClassInfo(Type type, LuaTable parameters) .Where(method => !method.IsSpecialName || ( ((method.Name == "get_Item" && method.GetParameters().Length == 1) || (method.Name == "set_Item" && method.GetParameters().Length == 2)) - && method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) + && method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) && type.GetCustomAttribute() == null ) ) .Concat(extension_methods) @@ -380,12 +380,14 @@ static void getClassInfo(Type type, LuaTable parameters) var indexers = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(prop => prop.GetIndexParameters().Length > 0); parameters.Set("indexers", indexers.Where(prop => prop.CanRead && (prop.GetGetMethod() != null)).Select(prop => prop.GetGetMethod()) - .Where(method => method.GetParameters().Length == 1 && !method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))) - .ToList()); + .Where(method => method.GetParameters().Length == 1 && (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) + || type.GetCustomAttribute() != null)) + .OrderBy(t => t.Name).ToList()); parameters.Set("newindexers", indexers.Where(prop => prop.CanWrite && (prop.GetSetMethod() != null)).Select(prop => prop.GetSetMethod()) - .Where(method => method.GetParameters().Length == 2 && !method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))) - .ToList()); + .Where(method => method.GetParameters().Length == 2 && (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) + || type.GetCustomAttribute() != null)) + .OrderBy(t => t.Name).ToList()); parameters.Set("events", type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly).Where(e => !isObsolete(e) && !isMemberInBlackList(e)) .Where(ev=> ev.GetAddMethod() != null || ev.GetRemoveMethod() != null) diff --git a/Assets/XLua/Src/GenAttributes.cs b/Assets/XLua/Src/GenAttributes.cs index a0339be45..8cddbd762 100644 --- a/Assets/XLua/Src/GenAttributes.cs +++ b/Assets/XLua/Src/GenAttributes.cs @@ -127,6 +127,11 @@ internal class HotfixDelegateAttribute : Attribute { } + public class LuaIndexerAttribute : Attribute + { + + } + #if !XLUA_GENERAL public static class SysGenConfig { diff --git a/Assets/XLua/Src/Utils.cs b/Assets/XLua/Src/Utils.cs index 0357352de..cae3db756 100644 --- a/Assets/XLua/Src/Utils.cs +++ b/Assets/XLua/Src/Utils.cs @@ -487,7 +487,7 @@ static void makeReflectionWrap(RealStatePtr L, Type type, int cls_field, int cls //indexer if (method.IsSpecialName && ((method.Name == "get_Item" && method.GetParameters().Length == 1) || (method.Name == "set_Item" && method.GetParameters().Length == 2))) { - if (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))) + if (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)) || type.GetCustomAttribute() != null) { continue; }