从C#Property getters返回Enum

cos*_*chy 2 c# visual-studio

如何从setter/getter函数返回枚举?

目前我有这个:

    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; 
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我尝试运行它时,我收到一个错误:

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;
        }
    }      
    }
Run Code Online (Sandbox Code Playgroud)

VisualStudio中的好处是属性网格允许您在ChoiceOne和ChoiceTwo之间设置正确的SetChoice属性.

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

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

希望这能澄清一些事情吗?

我们现在差不多了:)保持想法的到来.

谢谢

Mar*_*ell 15

它看起来像你想要的:

public Case ChooseCase
{
    get { return 'Condition' ? Case.Lower : Case.Upper; }
}
Run Code Online (Sandbox Code Playgroud)

或者我完全错过了这一点?