473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Structures with Enum-like IntelliSense support

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
10 2216
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
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
"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
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
"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
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
"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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Shwetabh | last post by:
Hi everyone. My question is, why are data structures implemented only with struct data type? Why not union when it is more efficient as compared with structures? Thanks in advance
11
by: Alfonso Morra | last post by:
Hi, I have the ff data types : typedef enum { VAL_LONG , VAL_DOUBLE , VAL_STRING , VAL_DATASET }ValueTypeEnum ;
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
2
by: Paul | last post by:
I have a situation that I want to work but don't know the proper way to handle it. I want to create a User Defined "Type" (structure, class or enumeration). I'm not sure what it should be or...
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
1
by: shrini | last post by:
Hi, Im using a map implementation that has structures as both the key and it value. Ive used as below: typedef struct RadioMeasurmentType { enum measurementId; uint32 radioCardId; uint32...
1
by: peary | last post by:
Hi, everyone, I'm writing a program to discover wireless network using Windows Native Wifi API & VB.net. I have to declare the windows API in my VB.net program. The original windows...
6
by: titan nyquist | last post by:
Can you make volatile structures in C#? I have a static class, to have "global" variables. This allows the whole program to see them. I make them "volatile" to avoid multi- threading accessing...
13
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.