473,765 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2246
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=anytypeenum s&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=anytypeenum s&lang=en>


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

I also discovered System.Componen tModel.TypeConv erter.GetStanda rdValues(),
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******** ******@tk2msftn gp13.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.Componen tModel).
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.Componen tModel).

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*******@free net.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 TypeConverterAt tribute. 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. GetStandardValu es 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******** ******@TK2MSFTN GP11.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.Componen tModel).
Thanks,
Michael

Nov 29 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1910
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
2012
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
3616
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(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
2
1409
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 where it should reside. I'll use Enum for this example. Currently in a Public Module: ---------------------------- Public Enum MyUserDefinedType
1
2461
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 installed the boost library. This is using gcc under FC3.
2
2120
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 installed the boost library. This is using gcc under FC3.
1
2611
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 radioPathId;
1
2132
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 declaration is as below. The problem is in "struct _WLAN_AVAILABLE_NETWORK_LIST", it declared "WLAN_AVAILABLE_NETWORK Network;". I think which means a Network array of struct WLAN_AVAILABLE_NETWORK.
6
3534
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 issues. That works. THE PROBLEM: In that static class, I want to combine some variables inside a structure, and then make a variable of that structure type,
13
3206
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 functions that require a structure to be passed to them. The function declaration in the .h file is of the form: SDCERR GetConfig(char *name, SDCConfig *cfg); where SDCConfig is a structure defined in the .h file. I am not much of a C (or C#)...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9955
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9833
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.