}                           // Require use of factory methods

        private static ObjectPermission GetNew(string name)
        {
            ObjectPermission op = new ObjectPermission();

            op._name = name;
            return(op);
        }
 internal static void Fill(ObjectPermission item, SqlDataReader dr)
 {
     item._name   = dr["Name"] as string;
     item._select = (dr["Select"] as int?) ?? 0;
     item._update = (dr["Update"] as int?) ?? 0;
     item._insert = (dr["Insert"] as int?) ?? 0;
     item._delete = (dr["Delete"] as int?) ?? 0;
 }
        /// <summary>
        /// Creates a new object permission object using the provided parameters.
        /// </summary>
        /// <param name="name">The name of the target object.</param>
        /// <param name="select">Whether select/view is permitted</param>
        /// <param name="update">Whether update is permitted</param>
        /// <param name="insert">Whether insert is permitted</param>
        /// <param name="delete">Whether delete is permitted</param>
        /// <returns>An ObjectPermission object with the specified permissions.</returns>
        /// <remarks>This method can be used to set custom permissions.</remarks>
        public static ObjectPermission GetNew(string name, bool select, bool update, bool insert, bool delete)
        {
            ObjectPermission op = new ObjectPermission();

            op._name   = name;
            op._select = select ? 1 : 0;
            op._update = update ? 1 : 0;
            op._insert = insert ? 1 : 0;
            op._delete = delete ? 1 : 0;
            return(op);
        }
        /// <summary>
        /// Creates a new object permission object using the provided parameters.
        /// </summary>
        /// <param name="name">The name of the target object.</param>
        /// <param name="select">Whether select/view is permitted</param>
        /// <param name="update">Whether update is permitted</param>
        /// <param name="insert">Whether insert is permitted</param>
        /// <param name="delete">Whether delete is permitted</param>
        /// <returns>An ObjectPermission object with the specified permissions.</returns>
        /// <remarks>This method can be used to set custom permissions.</remarks>
        public static ObjectPermission GetNew(string name, int select, int update, int insert, int delete)
        {
            ObjectPermission op = new ObjectPermission();

            op._name   = name;
            op._select = select;
            op._update = update;
            op._insert = insert;
            op._delete = delete;
            return(op);
        }
        /// <summary>
        /// Gets the effective database permissions for the current user for the
        /// specified object.
        /// </summary>
        /// <param name="objectName">The name of the object to get permissions for.</param>
        /// <returns>A new ObjectPermission containing the current users permissions
        /// for the specified object.</returns>
        public static ObjectPermission Load(string objectName)
        {
            ObjectPermission perm = GetNew(objectName);

            using (SqlConnection cn = DBConnect.NewDataConnection())
            {
                using (SqlCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "dbo.up_GetObjectPermissions";
                    cmd.Parameters.AddWithValue("@objectName", objectName);
                    using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (dr.Read())
                        {
                            Fill(perm, dr);
                        }
                    }
                }
                //cn.Close();
            }
            return(perm);
        }