Подтвердить что ты не робот

Дизайнер должен создать экземпляр... не может, потому что тип объявлен абстрактным

Visual Studio жалуется: Предупреждение 1 Дизайнер должен создать экземпляр типа "RentalEase.CustomBindingNavForm", но он не может, потому что тип объявлен как абстрактный.

Visual Studio не позволит мне получить доступ к конструктору для формы. Класс уже реализует все абстрактные методы из CustomBindingNavForm. CustomBindingNavForm предоставляет некоторые функции конкретные и абстрактные.

Есть ли способ обойти это?

Вот класс:

 public abstract class CustomBindingNavForm : SingleInstanceForm {     

        //Flags for managing BindingSource
        protected bool isNew = false;
        protected bool isUpdating = false;

        /// <summary>
        /// This is so that when a new item is added, it sets isNew and firstPass to true. The Position Changed Event will look for
        /// firstPass and if it is true set it to false. Then on the next pass, it will see it false and set isNew to false.
        /// This is needed because the Position Changed Event will fire when a new item is added.
        /// </summary>
        protected bool firstPass = false;


        protected abstract bool validateInput();
        protected abstract void saveToDatabase();


        //manipulating binding
        protected abstract void bindingSourceCancelResetCurrent();
        protected abstract void bindingSourceRemoveCurrent();
        protected abstract void bindingSourceMoveFirst();
        protected abstract void bindingSourceMoveNext();
        protected abstract void bindingSourceMoveLast();
        protected abstract void bindingSourceMovePrevious();
        protected abstract void bindingSourceAddNew();

        public void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                bindingSourceMovePrevious();
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {
                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                        bindingSourceMovePrevious();
                    }
                }
            }
        }

        public void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                saveToDatabase();
                bool temp = isUpdating;
                isUpdating = true;
                bindingSourceAddNew();
                isUpdating = temp;

                isNew = true;
                firstPass = true;
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {

                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                    }

                    bool temp = isUpdating;
                    isUpdating = true;
                    bindingSourceAddNew();
                    isUpdating = temp;

                    isNew = true;
                    firstPass = true;
                }
            }
        }

        public void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                bindingSourceMoveFirst();
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {
                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                    }
                    bindingSourceMoveFirst();
                }
            }
        }

        public void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                bindingSourceMoveNext();
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {
                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                    }
                    bindingSourceMoveNext();
                }
            }
        }
    }
4b9b3361

Ответ 1

Я не видел контент у городского картофеля (его вниз), но Me и Smelch придумали решение. Form сам наследуется от абстрактного класса, поэтому то, что они не говорят вам, состоит в том, что его только 1-й уровень наследования, который не может быть абстрактным, 2-й сверху вниз.

Оттуда это просто вопрос наличия пустого класса в середине и обертывания #if debug вокруг объявления форм, и вам хорошо идти. Просто убедитесь, что вы выходите в режиме выпуска и разрабатываете в режиме отладки (что очень типично).

Вы получите полную поддержку дизайнеров и реальный абстрактный базовый класс при разработке (отладке) и времени сборки (выпуска), потому что каждый раз, когда он заканчивается, используя ваш абстрактный базовый класс.

Полное объяснение и ответ здесь