views:

231

answers:

2

Is there a setting whereby intellisense in Visual Studio will also put variables in the intellisense pop up instead of just the values for the enumerated type? It obviously knows it is supposed to be an enumeration. Maybe this is just a mechanism to keep me from putting something in there that might cause an exception.

Consider the following setup: (It's a bit contrived, and I'm sorry about that.)

Public Enum PhraseEmphasis
   Monotone = 0
   Question
   Statement
   Exclamation
   CrazyExclamation
   QuestioningExclamation
   Cursing
End Enum

Private _emphasisFromCode as PhraseEmphasis

Public Function Speak(ByVal phrase As String, ByVal emphasis As PhraseEmphasis) as String
Select Case emphasis
  Case PhraseEmphasis.Question
    Return phrase + '?'
  Case PhraseEmphasis.Statement
    Return phrase + '.'
  Case PhraseEmphasis.Exclamation
    Return phrase + '!'
  Case PhraseEmphasis.CrazyExclamation
    Return phrase + '!!!1!eleven!!'
  Case PhraseEmphasis.QuestioningExclamation
    Return phrase + '?!'
  Case PhraseEmphasis.Cursing
    Return '!@#@%@#!'
  Case Else
    Return phrase
End Select
End Function

Now, in the code I have something that sets the _emphasisFromCode (obviously) and then I want to call the function. Then what happens when I start typing Speak("HelloWorld", ...) at the elipses there, I don't like the intellisense. The only thing that pops up in the intellisense is a list of all enumerations.

And now I have spent a disproportionate amount of time explaining this with respect to how much I actually care. However, my machine is really slow in compiling today.

+1  A: 
Ahmad Mageed
+1  A: 

No, there is no such setting. How could IntelliSense guess from your method signature, that you want to put an arbitrary value to the method, when the signature states exactly the opposite?

Instead, you may declare another enum member (say PhraseEmphasis.None = 0, which is recommended best practice anyway) and use that, or eventually declare the emphasis parameter with the optional keyword to avoid the need of providing it altogether.

Thomas Weller
A variable of enum type is not of arbitrary value. I would like to see the enums of that type also in the list.
Anthony Potts
This would contradict the enum concept. An enum is a _type_ that consists of a set of concrete values that have an underlying base type. So everything other than listing the values of this enum would not be in line with the concept of a strongly-typed programming language...
Thomas Weller