Example #1
0
            public override void Assign(ILuaValue value)
            {
                if (value.ValueType == LuaValueType.Table)
                {
                    // set the 'get' method for the item
                    var item = value.GetIndex(new LuaString("get"));
                    if (item != null && item != LuaNil.Nil)
                    {
                        MethodInfo m = _prop.GetGetMethod(true);
                        if (m == null || (!m.Attributes.HasFlag(MethodAttributes.Abstract) && !m.Attributes.HasFlag(MethodAttributes.Virtual)))
                        {
                            throw new InvalidOperationException(string.Format(Resources.CannotOverrideProperty, Name));
                        }
                        BoundTo = m;

                        if (item.ValueType != LuaValueType.Function)
                        {
                            throw new InvalidOperationException(Resources.PropTableFuncs);
                        }
                        Method = item;
                    }
                    // set the 'set' method for the item
                    item = value.GetIndex(new LuaString("set"));
                    if (item != null && item != LuaNil.Nil)
                    {
                        MethodInfo m = _prop.GetSetMethod(true);
                        if (m == null || (!m.Attributes.HasFlag(MethodAttributes.Abstract) && !m.Attributes.HasFlag(MethodAttributes.Virtual)))
                        {
                            throw new InvalidOperationException(string.Format(Resources.CannotOverrideProperty, Name));
                        }
                        BoundSet = m;

                        if (item.ValueType != LuaValueType.Function)
                        {
                            throw new InvalidOperationException(Resources.PropTableFuncs);
                        }
                        MethodSet = item;
                    }
                }
                else
                {
                    MethodInfo m = _prop.GetGetMethod(true);
                    if (m == null || (!m.Attributes.HasFlag(MethodAttributes.Abstract) && !m.Attributes.HasFlag(MethodAttributes.Virtual)))
                    {
                        throw new InvalidOperationException(string.Format(Resources.CannotOverrideProperty, Name));
                    }
                    BoundTo = m;

                    // check if the set method is abstract, if it is, we need to implement that also.
                    m = _prop.GetSetMethod(true);
                    if (m != null && (m.Attributes & MethodAttributes.Abstract) == MethodAttributes.Abstract)
                    {
                        BoundSet = m;
                    }

                    Default = value;
                }
            }