private static int newindexInt(IntPtr l, object self, int index)
        {
            Type type = LuaVarObject.getType(self);

            if (self is IList)
            {
                if (type.IsGenericType)
                {
                    Type t = type.GetGenericArguments()[0];
                    (self as IList)[index] = LuaObject.changeType(LuaObject.checkVar(l, 3), t);
                }
                else
                {
                    (self as IList)[index] = LuaObject.checkVar(l, 3);
                }
            }
            else if (self is IDictionary)
            {
                Type   t2  = type.GetGenericArguments()[0];
                object obj = index;
                obj = LuaObject.changeType(obj, t2);
                if (type.IsGenericType)
                {
                    Type t3 = type.GetGenericArguments()[1];
                    (self as IDictionary)[obj] = LuaObject.changeType(LuaObject.checkVar(l, 3), t3);
                }
                else
                {
                    (self as IDictionary)[obj] = LuaObject.checkVar(l, 3);
                }
            }
            LuaObject.pushValue(l, true);
            return(1);
        }
        private static int indexInt(IntPtr l, object self, int index)
        {
            Type type = LuaVarObject.getType(self);

            if (self is IList)
            {
                LuaObject.pushValue(l, true);
                LuaObject.pushVar(l, (self as IList)[index]);
                return(2);
            }
            if (self is IDictionary)
            {
                IDictionary dictionary = (IDictionary)self;
                object      obj        = index;
                if (type.IsGenericType)
                {
                    Type type2 = type.GetGenericArguments()[0];
                    if (type2.IsEnum)
                    {
                        LuaObject.pushValue(l, true);
                        LuaObject.pushVar(l, dictionary[Enum.Parse(type2, obj.ToString())]);
                        return(2);
                    }
                    obj = LuaObject.changeType(obj, type2);
                }
                LuaObject.pushValue(l, true);
                LuaObject.pushVar(l, dictionary[obj]);
                return(2);
            }
            return(0);
        }
        private static int indexString(IntPtr l, object self, string key)
        {
            Type type = LuaVarObject.getType(self);

            if (self is IDictionary)
            {
                if (!type.IsGenericType || type.GetGenericArguments()[0] == typeof(string))
                {
                    object obj = (self as IDictionary)[key];
                    if (obj != null)
                    {
                        LuaObject.pushValue(l, true);
                        LuaObject.pushVar(l, obj);
                        return(2);
                    }
                }
            }
            IList <MemberInfo> cacheMembers = LuaVarObject.GetCacheMembers(type, key);

            if (cacheMembers == null || cacheMembers.Count == 0)
            {
                return(LuaObject.error(l, "Can't find " + key));
            }
            LuaObject.pushValue(l, true);
            MemberInfo  memberInfo = cacheMembers[0];
            MemberTypes memberType = memberInfo.MemberType;

            switch (memberType)
            {
            case MemberTypes.Event:
                return(2);

            case MemberTypes.Constructor | MemberTypes.Event:
            {
IL_B3:
                if (memberType == MemberTypes.Method)
                {
                    LuaCSFunction o = new LuaCSFunction(new LuaVarObject.MethodWrapper(self, cacheMembers).invoke);
                    LuaObject.pushObject(l, o);
                    return(2);
                }
                if (memberType != MemberTypes.Property)
                {
                    return(1);
                }
                PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
                MethodInfo   getMethod    = propertyInfo.GetGetMethod(true);
                LuaObject.pushVar(l, getMethod.Invoke(self, null));
                return(2);
            }

            case MemberTypes.Field:
            {
                FieldInfo fieldInfo = (FieldInfo)memberInfo;
                LuaObject.pushVar(l, fieldInfo.GetValue(self));
                return(2);
            }
            }
            goto IL_B3;
        }
        private static int newindexString(IntPtr l, object self, string key)
        {
            if (self is IDictionary)
            {
                Type type = LuaVarObject.getType(self);
                Type t    = type.GetGenericArguments()[1];
                (self as IDictionary)[key] = LuaObject.checkVar(l, 3, t);
                return(LuaObject.ok(l));
            }
            Type type2 = LuaVarObject.getType(self);
            IList <MemberInfo> cacheMembers = LuaVarObject.GetCacheMembers(type2, key);

            if (cacheMembers == null || cacheMembers.Count == 0)
            {
                return(LuaObject.error(l, "Can't find " + key));
            }
            MemberInfo  memberInfo = cacheMembers[0];
            MemberTypes memberType = memberInfo.MemberType;

            switch (memberType)
            {
            case MemberTypes.Event:
                return(LuaObject.error(l, "Event can't set"));

            case MemberTypes.Constructor | MemberTypes.Event:
            {
IL_8F:
                if (memberType == MemberTypes.Method)
                {
                    return(LuaObject.error(l, "Method can't set"));
                }
                if (memberType != MemberTypes.Property)
                {
                    goto IL_121;
                }
                PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
                MethodInfo   setMethod    = propertyInfo.GetSetMethod(true);
                object       obj          = LuaObject.checkVar(l, 3, propertyInfo.PropertyType);
                setMethod.Invoke(self, new object[]
                    {
                        obj
                    });
                goto IL_121;
            }

            case MemberTypes.Field:
            {
                FieldInfo fieldInfo = (FieldInfo)memberInfo;
                object    value     = LuaObject.checkVar(l, 3, fieldInfo.FieldType);
                fieldInfo.SetValue(self, value);
                goto IL_121;
            }
            }
            goto IL_8F;
IL_121:
            return(LuaObject.ok(l));
        }
 private static int newindexObject(IntPtr l, object self, object k, object v)
 {
     if (self is IDictionary)
     {
         IDictionary dictionary = self as IDictionary;
         Type        type       = LuaVarObject.getType(self);
         Type        t          = type.GetGenericArguments()[1];
         object      value      = LuaObject.changeType(v, t);
         dictionary[k] = value;
     }
     return(LuaObject.ok(l));
 }