/// <summary>
        /// Raises an appropriate ScriptRuntimeException if the specified access is not supported.
        /// Checks are made for the MemberDescriptorAccess permissions AND for the access of instance
        /// members through static userdatas.
        /// </summary>
        /// <param name="desc">The desc.</param>
        /// <param name="access">The access.</param>
        /// <param name="obj">The object to be checked for access.</param>
        public static void CheckAccess(this IMemberDescriptor desc, MemberDescriptorAccess access, object obj)
        {
            if (!desc.IsStatic && obj == null)
            {
                throw ScriptRuntimeException.AccessInstanceMemberOnStatics(desc);
            }

            if (access.HasAllFlags(MemberDescriptorAccess.CanExecute) && !desc.CanExecute())
            {
                throw new ScriptRuntimeException("userdata member {0} cannot be called.", desc.Name);
            }

            if (access.HasAllFlags(MemberDescriptorAccess.CanWrite) && !desc.CanWrite())
            {
                throw new ScriptRuntimeException("userdata member {0} cannot be assigned to.", desc.Name);
            }

            if (access.HasAllFlags(MemberDescriptorAccess.CanRead) && !desc.CanRead())
            {
                throw new ScriptRuntimeException("userdata member {0} cannot be read from.", desc.Name);
            }
        }