如何从设置器/获取器函数返回枚举?

目前我有这个:

    public enum LowerCase
    {
        a,
        b,
    }
    public enum UpperCase
    {
        A,
        B,
    }

    public enum Case
    {
        Upper,
        Lower,
    }

    private Enum _Case;
    private Enum _ChosenCase;


    public Enum ChooseCase
    {
        get
        {
            if ('Condition')
            {
                return LowerCase; //[need to return LowerCase]
            }
            else
            {
                return UpperCase; //[need to return UpperCase]
            }
        }
        set
        {
            _ChosenCase = value;
        }
    }


当我尝试运行此命令时,出现错误:

LowerCase是“类型”,但像“变量”一样使用

任何想法我需要做些什么来返回一个枚举?

我也不太确定当前是否设置该值。

如果有人可以提供一些一般性建议,我将不胜感激。大多数人应该能够看到我正在尝试做的事情。

非常感谢。

[最新编辑]

首先感谢所有答复。

为了简化这个问题,似乎我使用了大写/小写的错误类比,并且你们中有些人有错误的想法-显然不是您的错:)

这是我到目前为止的代码,可让您在ChoiceOne和ChoiceTwo之间进行选择

    public partial class CustomControl1 : Control
    {
    public enum ChoiceOne
    {
        SubChoiceA,
        SubChoiceB,
    }
    public enum ChoiceTwo
    {
        SubChoiceC,
        SubChoiceD,
    }
    public enum Choice
    {
        ChoiceOne,
        ChoiceTwo,
    }

    private Type _subChoice;
    private Choice _choice;

    public Type SetSubChoice
    {
        get
        {
            if (_choice.Equals(Choice.ChoiceOne))
            {
                return typeof(ChoiceOne);
            }
            else
            {
                return typeof(ChoiceTwo);
            }
        }
        set
        {
            _subChoice = value;
        }
    }

    public Choice SetChoice
    {
        get
        {
            return _choice;
        }
        set
        {
            _choice = value;
        }
    }
    }


在VisualStudio中发生的是,属性网格允许您在ChoiceOne和ChoiceTwo之间设置正确的SetChoice属性。

问题是SetSubChoice属性显示为灰色,但取决于SetChoice设置为WindowsFormsApplication4.CustomControl1 + ChoiceOne或WindowsFormsApplication4.CustomControl1 + ChoiceTwo。我想要的是能够使用SetSubChoice选择SetChoice设置为SubChoiceA或SubChoiceB或SubChoiceC或SubChoiceD。

因此,例如,如果将SetChoice设置为ChoiceOne,则SetSubChoice将允许我在ChoiceA或ChoiceB之间进行选择。
同样,如果将SetChoice设置为ChoiceTwo,则SetSubChoice将允许我在ChoiceC或ChoiceD之间进行选择。

希望这可以使事情澄清一些?

我们现在就快到了:)不断提出建议。

谢谢

最佳答案

看起来像您想要的:

public Case ChooseCase
{
    get { return 'Condition' ? Case.Lower : Case.Upper; }
}


还是我完全错过了重点?

07-26 08:08