By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,350 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,350 IT Pros & Developers. It's quick & easy.

Structures with Enum-like IntelliSense support

P: n/a
Hello,

does anyone know how to produce a data type which offers Enum-like
IntelliSense in VS 2005?
What I am trying to create is a type which is very similar to an enum, i.e.
has a fixed set of values, but provides some more methods. Unfortunately,
you cannot derive from System.Enum to do this.

I noticed that if you type "Dim C as System.Drawing.Color = ", the editor
will display a list of colors, but this are actually ReadOnly Shared
Properties of the Color structure. So there must be a way to map structure
members to enum constants...

Any ideas how to do this?
Thanks in advance!

Michael
Nov 28 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Michael,

"Michael Feld" <mf***@t-online.de> schrieb:
does anyone know how to produce a data type which offers Enum-like
IntelliSense in VS 2005?
[...]
I noticed that if you type "Dim C as System.Drawing.Color = ", the editor
will display a list of colors, but this are actually ReadOnly Shared
Properties of the Color structure. So there must be a way to map structure
members to enum constants...


There is no automatic way to do that.

Creating enumerations of items with a certain arbitrary data type
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 28 '05 #2

P: n/a
Hello Herfried,

thanks for the quick reply!
I noticed that if you type "Dim C as System.Drawing.Color = ", the
editor will display a list of colors, but this are actually ReadOnly
Shared Properties of the Color structure. So there must be a way to map
structure members to enum constants...
There is no automatic way to do that.


So is there any way at all to do this? Or is System.Color and others somehow
"hard-coded" into the VS2005 IntelliSense?
Creating enumerations of items with a certain arbitrary data type
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&lang=en>


This is what I started with too. It works well, but the IDE support is
missing.

I also discovered System.ComponentModel.TypeConverter.GetStandardVal ues(),
but this worked only for the Windows Forms designer, not for the code
editor.
Thanks anyway,

Michael
Nov 28 '05 #3

P: n/a
"Michael Feld" <mf***@t-online.de> schrieb:
> I noticed that if you type "Dim C as System.Drawing.Color = ", the
> editor will display a list of colors, but this are actually ReadOnly
> Shared Properties of the Color structure. So there must be a way to map
> structure members to enum constants...


There is no automatic way to do that.


So is there any way at all to do this? Or is System.Color and others
somehow "hard-coded" into the VS2005 IntelliSense?


The .NET Framework contains a 'KnownColor' enumeration and color /objects/
which are exposed by the 'Color' structure. Are you talking about support
in the property grid?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 28 '05 #4

P: n/a
Michael,
| Any ideas how to do this?
Yes! You already answered your own question:

| this are actually ReadOnly Shared
| Properties of the Color structure

You need to define your Structure, then you need to define Readonly Shared
Properties or Fields on that structure. Generally I use Readonly Shared
Fields as they are "easier" to define then properties...

Something like:

Public Structure Widget

Private ReadOnly m_value As Integer

Private Sub New(ByVal value As Integer)
m_value = value
End Sub

Public Shared ReadOnly Value1 As New Widget(1)
Public Shared ReadOnly Value2 As New Widget(2)
Public Shared ReadOnly Value3 As New Widget(3)
Public Shared ReadOnly Value4 As New Widget(4)

Public Sub Method1()

Public Function Method2() As Something

...

End Structure

I defined the constructor Private as there are a "fixed set of values" on
the Widget class, namely Value1, Value2, Value3, and Value4.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Michael Feld" <mf***@t-online.de> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
| Hello,
|
| does anyone know how to produce a data type which offers Enum-like
| IntelliSense in VS 2005?
| What I am trying to create is a type which is very similar to an enum,
i.e.
| has a fixed set of values, but provides some more methods. Unfortunately,
| you cannot derive from System.Enum to do this.
|
| I noticed that if you type "Dim C as System.Drawing.Color = ", the editor
| will display a list of colors, but this are actually ReadOnly Shared
| Properties of the Color structure. So there must be a way to map structure
| members to enum constants...
|
| Any ideas how to do this?
|
|
| Thanks in advance!
|
| Michael
|
|
Nov 28 '05 #5

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote:
"Michael Feld" <mf***@t-online.de> schrieb:
> I noticed that if you type "Dim C as System.Drawing.Color = ", the
> editor will display a list of colors, but this are actually ReadOnly
> Shared Properties of the Color structure. So there must be a way to
> map structure members to enum constants...

There is no automatic way to do that.


So is there any way at all to do this? Or is System.Color and others
somehow "hard-coded" into the VS2005 IntelliSense?


The .NET Framework contains a 'KnownColor' enumeration and color /objects/
which are exposed by the 'Color' structure. Are you talking about support
in the property grid?


I am not talking about making the custom enum work programatically. This
point is clear. It's also not about the property grid (I got this to work in
an example, anyway). But if you are working in the code editor and you want
to specify a value for an object of the type of this "custom enumeration"
(the structure!), then you would want to have a list of values pop up as
soon as you come to a place where such a value has to be specified.

Another example:
Create a class with

Public Sub Foo(ByVal Bar As Color)
End Sub

Now from any valid place in code, try to call Foo and type

Foo(

and you will get a list of shared read-only properties (!) of "Color" from
which you can select, as if it was an enumeration.
If I try the same with my own structure, I do not get this list (unless I
type "<Classname>.", but this includes methods and other properties too).

So, is it now more clear what I am trying to accomplish?
Michael
Nov 29 '05 #6

P: n/a
Hello Jay!

I tried your code, but I just don't get the IntelliSense to work. My
question was in fact all about this feature.

Maybe you can try this and tell me if I am doing something wrong:

If I type
Dim C as new Color =
in the editor, a list of possible values pops up.

But when I type
Dim W as new Widget =
(creating the class you posted before) nothing happens.

So there has to be either a major difference between the implementation of
"Color" and "Widget", or - as I said earlier - IntelliSense is hard-coded
into the IDE for "Color" (which would somehow surprise me looking at how
many options you can find in System.ComponentModel).
Thanks,
Michael
Nov 29 '05 #7

P: n/a
"Michael Feld" <mf***@t-online.de> schrieb
Hello Jay!

I tried your code, but I just don't get the IntelliSense to work. My
question was in fact all about this feature.

Maybe you can try this and tell me if I am doing something wrong:

If I type
Dim C as new Color =
in the editor, a list of possible values pops up.

But when I type
Dim W as new Widget =
(creating the class you posted before) nothing happens.

So there has to be either a major difference between the
implementation of "Color" and "Widget", or - as I said earlier -
IntelliSense is hard-coded into the IDE for "Color" (which would
somehow surprise me looking at how many options you can find in
System.ComponentModel).

I think I know what you mean, but in my IDE, there is no item listed after
typing "Dim C as new color =". In addition, 'New' doesn't make sense in this
case because the new object would be overwritten by the object after "="
anyway. Apart from this, if you write "Dim c as color =", no combobox pops
up. It would only popup if you write "dim c as color = color.", and how to
implement this in your own class, Jay has already shown you.

Armin

Nov 29 '05 #8

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb
I think I know what you mean, but in my IDE, there is no item listed
after typing "Dim C as new color =". In addition, 'New' doesn't make
sense in this case because the new object would be overwritten by
the object after "=" anyway. Apart from this, if you write "Dim c as
color =", no combobox pops up. It would only popup if you write "dim
c as color = color.", and how to implement this in your own class,
Jay has already shown you.


Sorry, I didn't read you are using VB 2005. I was referring to VB 2003. (I
didn't know and read there is a difference) Yes, in VB 2005, i get the popup
combo but I cannot answer why, yet.
Armin

Nov 29 '05 #9

P: n/a
Michael,
I have not tried it, I suspect its the ColorConverter that is attached to
the Color structure via the TypeConverterAttribute. Of course it may be one
of the other custom attributes attached to the Color structure, such as the
EditorAttribute...

I would expect that the ColorConverter.GetStandardValues is the method
returning the values...

However I have only used type converters in relation to the Property Grid in
..NET 1.1, I don't know specifically if their use has been expanded to the
IDE in VS 2005 (.NET 2.0) it would be cool if they were.

If I have time later today, I will play with creating a converter...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Michael Feld" <mf***@t-online.de> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
Hello Jay!

I tried your code, but I just don't get the IntelliSense to work. My
question was in fact all about this feature.

Maybe you can try this and tell me if I am doing something wrong:

If I type
Dim C as new Color =
in the editor, a list of possible values pops up.

But when I type
Dim W as new Widget =
(creating the class you posted before) nothing happens.

So there has to be either a major difference between the implementation of
"Color" and "Widget", or - as I said earlier - IntelliSense is hard-coded
into the IDE for "Color" (which would somehow surprise me looking at how
many options you can find in System.ComponentModel).
Thanks,
Michael

Nov 29 '05 #10

P: n/a
Hello again,

did you find anything out about the ColorConverter?

I tried to create such a converter for my class too (by looking at the
disassembly for ColorConverter), but it still doesn't have the same
IntelliSense as Color.
I also first thought about this attribute, but the fact the IntelliSense
tooltip reads "Public Shared Property ..." puzzles me... because the
TypeConvertes does not seem to provide this information.
And the ColorEditor appears even more unlikely to me.
After all, the same IntelliSense works for System.Drawing.Brush, and this
class has no attributes at all.

Seems there is some kind of magic going on in VS...
Regards,
Michael

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb im
Newsbeitrag news:Oi*************@tk2msftngp13.phx.gbl...
Michael,
I have not tried it, I suspect its the ColorConverter that is attached to
the Color structure via the TypeConverterAttribute. Of course it may be
one of the other custom attributes attached to the Color structure, such
as the EditorAttribute...

I would expect that the ColorConverter.GetStandardValues is the method
returning the values...

However I have only used type converters in relation to the Property Grid
in .NET 1.1, I don't know specifically if their use has been expanded to
the IDE in VS 2005 (.NET 2.0) it would be cool if they were.

If I have time later today, I will play with creating a converter...


Dec 1 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.