February
18

Switch Code Snippet For Enums

Posted In: C# by rauchy

Perhaps this is a well-known feature and I’m a moron for posting about it, but I just noticed the switch code snippet.

I was working with this enum:

    public enum AvatarSource
    {
        Gravatar, Uploaded, Web
    }

and I wanted some conditional logic performed, depending on an AvatarSource instance. So I started to type switch and then thought I might use a code snippet for it, so I pressed TAB twice.

Well, I didn’t see this coming.

            switch (avatarSource)
            {
                case AvatarSource.Gravatar:
                    break;
                case AvatarSource.Uploaded:
                    break;
                case AvatarSource.Web:
                    break;
                default:
                    break;
            }

Once you enter the variable for your switch block, the snippet automatically adds a block for each value in your enum.

Sweet.

kick it on DotNetKicks.com

Something to say?

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.