Can an enum start empty and be added to on the fly? 15 16618
"apm" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:wWe2f.9538$U%5.5934@lakeread05... Can an enum start empty and be added to on the fly?
AFAIK, no.
"apm" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:wWe2f.9538$U%5.5934@lakeread05... Can an enum start empty and be added to on the fly?
I'll make it definative. No.
What are you trying to do? Chances are there is another pattern to pull it
off since enums that are modified at runtime really don't make a whole lot
of sense.
Well maybe your own enum can:
sealed class MyEnum
{
private String name;
private static int nextOrdinal= 1;
private int ordinal= nextOrdinal++;
private MyEnum(String name)
{
this.name= name;
}
public override String ToString()
{
return name;
}
public int ToOrdinal()
{
return ordinal;
}
public static MyEnum INVALID= new MyEnum("Invalid"); // ordinal 1
public static MyEnum OPENED= new MyEnum("Opened"); // ordinal 2
public static MyEnum CLOSED=new MyEnum("Closed"); // ordinal 3
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Console.WriteLine(MyEnum.OPENED.ToString());
Console.WriteLine(MyEnum.OPENED.ToOrdinal().ToStri ng());
Console.WriteLine(MyEnum.INVALID.ToString());
Console.WriteLine(MyEnum.INVALID.ToOrdinal().ToStr ing());
Console.WriteLine(MyEnum.CLOSED.ToString());
Console.WriteLine(MyEnum.CLOSED.ToOrdinal().ToStri ng());
Console.ReadLine();
}
}
Regards,
Jeff
*** Sent via Developersdex http://www.developersdex.com ***
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl... "apm" <Co*********@AdsorptionProcessModeling.com> wrote in message news:wWe2f.9538$U%5.5934@lakeread05... Can an enum start empty and be added to on the fly?
I'll make it definative. No.
What are you trying to do? Chances are there is another pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
Sure they do.
Picture this: a distributed application, in which the messages sent between
processes include enums. It's possible for machine A running version 1.0 to
communicate with machine B running 2.0. It's also possible that new values
were added to enums in newer version.
So, A receives a message from B containing an enum value it wasn't compiled
with. It would be nice if A could represent it as a value of the enum that
wasn't present at compilation time, and update the enum's internal
structures so that GetNames(), GetValue(), etc. process it correctly. That
way, if the message is "deserialized" (using the term loosely) into an
object, the cases of known and unknown enum value can be treated alike (i.e.
in both cases the object has a field whose type is the enum.)
It's possible (not even hard) to build something similar to an enum that can
do this, but it would be nice if enums had this ability built in. (By the
way, it turns out to be handy to be able to distinguish compile-time from
dynamic enum values. For example, if you're building a list for users to
pick values from, you often want to restrict it to compile-time values.)
"Mike Schilling" <ms*************@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP14.phx.gbl... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... "apm" <Co*********@AdsorptionProcessModeling.com> wrote in message news:wWe2f.9538$U%5.5934@lakeread05... Can an enum start empty and be added to on the fly?
I'll make it definative. No.
What are you trying to do? Chances are there is another pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
Sure they do.
Picture this: a distributed application, in which the messages sent between processes include enums. It's possible for machine A running version 1.0 to communicate with machine B running 2.0. It's also possible that new values were added to enums in newer version.
So, A receives a message from B containing an enum value it wasn't compiled with. It would be nice if A could represent it as a value of the enum that wasn't present at compilation time, and update the enum's internal structures so that GetNames(), GetValue(), etc. process it correctly. That way, if the message is "deserialized" (using the term loosely) into an object, the cases of known and unknown enum value can be treated alike (i.e. in both cases the object has a field whose type is the enum.)
It's possible (not even hard) to build something similar to an enum that can do this, but it would be nice if enums had this ability built in. (By the way, it turns out to be handy to be able to distinguish compile-time from dynamic enum values. For example, if you're building a list for users to pick values from, you often want to restrict it to compile-time values.)
I never really considered enums more than a language nicety. They have a
modicum of use outside of that, I suppose, but a dictionary works just as
well when working with widely dynamic values.
Even if you take a larger view of enums, I don't think it really makes sense
to add it. As you pointed out, being able to distinguish between compile
time, static enums(what we use every day) and dynamic enums(which as you
pointed out is easy to write) is nessecery, so why try to merge the two and
complicate the whole system to add functionality that would take 10 minutes
of work to write yourself, especially when it offers no language level
advantages(which is why enums pass, they are simple, language level
additions, this would be a runtime addition). Adding a class to handle this
situation would be acceptable, but they just don't make sense in enums.
"Daniel O'Connell > What are you trying to do? Chances are there is another
pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
I'm want to give the user a set of choices that will present themselves as
an enumeration in intellisence. It would be easier to write the code if the
values of the enum could be read from a file. I suppose a macro can be
written to help write the code.
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl... "Mike Schilling" <ms*************@hotmail.com> wrote in message news:uK**************@TK2MSFTNGP14.phx.gbl... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... "apm" <Co*********@AdsorptionProcessModeling.com> wrote in message news:wWe2f.9538$U%5.5934@lakeread05... Can an enum start empty and be added to on the fly?
I'll make it definative. No.
What are you trying to do? Chances are there is another pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
Sure they do.
Picture this: a distributed application, in which the messages sent between processes include enums. It's possible for machine A running version 1.0 to communicate with machine B running 2.0. It's also possible that new values were added to enums in newer version.
So, A receives a message from B containing an enum value it wasn't compiled with. It would be nice if A could represent it as a value of the enum that wasn't present at compilation time, and update the enum's internal structures so that GetNames(), GetValue(), etc. process it correctly. That way, if the message is "deserialized" (using the term loosely) into an object, the cases of known and unknown enum value can be treated alike (i.e. in both cases the object has a field whose type is the enum.)
It's possible (not even hard) to build something similar to an enum that can do this, but it would be nice if enums had this ability built in. (By the way, it turns out to be handy to be able to distinguish compile-time from dynamic enum values. For example, if you're building a list for users to pick values from, you often want to restrict it to compile-time values.)
I never really considered enums more than a language nicety. They have a modicum of use outside of that, I suppose, but a dictionary works just as well when working with widely dynamic values.
Even if you take a larger view of enums, I don't think it really makes sense to add it. As you pointed out, being able to distinguish between compile time, static enums(what we use every day) and dynamic enums(which as you pointed out is easy to write) is nessecery, so why try to merge the two and complicate the whole system to add functionality that would take 10 minutes of work to write yourself, especially when it offers no language level advantages(which is why enums pass, they are simple, language level additions, this would be a runtime addition). Adding a class to handle this situation would be acceptable, but they just don't make sense in enums.
Becasue enums nicely do 90% of what I want, and it would be nicer to reuse
and extend that functionality rather than have to duplicate it. You know,
what OOP is supposed to be good at :-)
"apm" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:dGE2f.12220$U%5.8789@lakeread05... "Daniel O'Connell > What are you trying to do? Chances are there is another pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
I'm want to give the user a set of choices that will present themselves as an enumeration in intellisence. It would be easier to write the code if the values of the enum could be read from a file. I suppose a macro can be written to help write the code.
Intellisense is a compile time thing, built entirely on static code
knowledge. It doesn't make sense to change things at runtime and expect them
to change at compile time as well. Are you trying to generate code files?
"Mike Schilling" <ms*************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... "Mike Schilling" <ms*************@hotmail.com> wrote in message news:uK**************@TK2MSFTNGP14.phx.gbl... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...
"apm" <Co*********@AdsorptionProcessModeling.com> wrote in message news:wWe2f.9538$U%5.5934@lakeread05... > Can an enum start empty and be added to on the fly?
I'll make it definative. No.
What are you trying to do? Chances are there is another pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
Sure they do.
Picture this: a distributed application, in which the messages sent between processes include enums. It's possible for machine A running version 1.0 to communicate with machine B running 2.0. It's also possible that new values were added to enums in newer version.
So, A receives a message from B containing an enum value it wasn't compiled with. It would be nice if A could represent it as a value of the enum that wasn't present at compilation time, and update the enum's internal structures so that GetNames(), GetValue(), etc. process it correctly. That way, if the message is "deserialized" (using the term loosely) into an object, the cases of known and unknown enum value can be treated alike (i.e. in both cases the object has a field whose type is the enum.)
It's possible (not even hard) to build something similar to an enum that can do this, but it would be nice if enums had this ability built in. (By the way, it turns out to be handy to be able to distinguish compile-time from dynamic enum values. For example, if you're building a list for users to pick values from, you often want to restrict it to compile-time values.)
I never really considered enums more than a language nicety. They have a modicum of use outside of that, I suppose, but a dictionary works just as well when working with widely dynamic values.
Even if you take a larger view of enums, I don't think it really makes sense to add it. As you pointed out, being able to distinguish between compile time, static enums(what we use every day) and dynamic enums(which as you pointed out is easy to write) is nessecery, so why try to merge the two and complicate the whole system to add functionality that would take 10 minutes of work to write yourself, especially when it offers no language level advantages(which is why enums pass, they are simple, language level additions, this would be a runtime addition). Adding a class to handle this situation would be acceptable, but they just don't make sense in enums.
Becasue enums nicely do 90% of what I want, and it would be nicer to reuse and extend that functionality rather than have to duplicate it. You know, what OOP is supposed to be good at :-)
Enums, atleast the .NET version, are pretty bad OOP IMHO. No inheritance, no
polymorphism, just flat value with a type.
Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote: Becasue enums nicely do 90% of what I want, and it would be nicer to reuse and extend that functionality rather than have to duplicate it. You know, what OOP is supposed to be good at :-)
Enums, atleast the .NET version, are pretty bad OOP IMHO. No inheritance, no polymorphism, just flat value with a type.
Indeed - bring on the Java enumerations! (They have a few wrinkles, but
generally they're incredibly handy.)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote: > Becasue enums nicely do 90% of what I want, and it would be nicer to > reuse > and extend that functionality rather than have to duplicate it. You > know, > what OOP is supposed to be good at :-)
Enums, atleast the .NET version, are pretty bad OOP IMHO. No inheritance, no polymorphism, just flat value with a type.
Indeed - bring on the Java enumerations! (They have a few wrinkles, but generally they're incredibly handy.)
I have to agree, I'm starting to like some of the advantages more and more.
Although I don't think traditional inheritance is going to happen within the
..NET framework(changing enums from value types to reference types is a huge
change), allowing method definitions, including a basic set of operations
like IsSet(), Set(), and Unset() for [Flags] enums, would certainly help
alot. Some form of enum composition might not be a bad idea either.
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl... "apm" <Co*********@AdsorptionProcessModeling.com> wrote in message news:dGE2f.12220$U%5.8789@lakeread05... "Daniel O'Connell > What are you trying to do? Chances are there is another pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
I'm want to give the user a set of choices that will present themselves as an enumeration in intellisence. It would be easier to write the code if the values of the enum could be read from a file. I suppose a macro can be written to help write the code.
Intellisense is a compile time thing, built entirely on static code knowledge. It doesn't make sense to change things at runtime and expect them to change at compile time as well. Are you trying to generate code files?
I think that is the only option with .NET. COM seems so much more
powerful than .NET.
"apm" <Co*********@AdsorptionProcessModeling.com> wrote in message
news:lUP2f.12607$U%5.2339@lakeread05... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... "apm" <Co*********@AdsorptionProcessModeling.com> wrote in message news:dGE2f.12220$U%5.8789@lakeread05... "Daniel O'Connell > What are you trying to do? Chances are there is another pattern to pull it off since enums that are modified at runtime really don't make a whole lot of sense.
I'm want to give the user a set of choices that will present themselves as an enumeration in intellisence. It would be easier to write the code if the values of the enum could be read from a file. I suppose a macro can be written to help write the code.
Intellisense is a compile time thing, built entirely on static code knowledge. It doesn't make sense to change things at runtime and expect them to change at compile time as well. Are you trying to generate code files?
I think that is the only option with .NET. COM seems so much more powerful than .NET.
Come again? I don't really know what you are trying to achieve, let alone
waht you mean here.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote: > Becasue enums nicely do 90% of what I want, and it would be nicer to > reuse > and extend that functionality rather than have to duplicate it. You > know, > what OOP is supposed to be good at :-)
Enums, atleast the .NET version, are pretty bad OOP IMHO. No inheritance, no polymorphism, just flat value with a type.
Indeed - bring on the Java enumerations! (They have a few wrinkles, but generally they're incredibly handy.)
Can't add to those dynamically either (At least in any supported way. I
haven't tried to hack into the $VALUES array.)
Mike Schilling <ms*************@hotmail.com> wrote: Indeed - bring on the Java enumerations! (They have a few wrinkles, but generally they're incredibly handy.)
Can't add to those dynamically either (At least in any supported way. I haven't tried to hack into the $VALUES array.)
No, you can't add to them - but they stil have fabulous advantages
compared with .NET enums.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dev |
last post by:
Dear Friends,
Is it possible to add the Enum in dynamically.
Like Ex:
enum Colors
{
Green, Red,Yellow,Blue,Orange
}
So i want add 6th name Black to Colors.Is it possible? If so how?...If...
|
by: Jigar Mehta |
last post by:
Hye,
This is Jigar mehta from India. I have made one application that adds
dynamic menu items from the database. Each menu item has one ID and menu
item's text is coming from the database. Now, I...
|
by: Ryu |
last post by:
I am having a problem whereby the controls (along with its values) disappear
after I click a button. The controls that I have added is a textbox in a
Table. Both of these displayed correctly. Any...
|
by: Jeffrey Todd |
last post by:
I have successfully created functionality that mostly models what I'm trying
to do - which is dynamically insert controls into a user control (ascx), and
insert validation controls, also...
|
by: Sudhakara.T.P. |
last post by:
Hi,
I want to populate my Enum dynamically from the database. Is that possible?
If so, what is the approach that I need to take.
I need this because I have some set of constants in my table...
|
by: Dennis Fazekas |
last post by:
Greetings,
I am creating a web form which will all the user to add an unlimited number
of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to
remove, and a "Save" button....
|
by: James Black |
last post by:
I am dynamically generating a table in IE to display some information.
I will probably change it to divs later, but I just want to get it
working properly first.
In my div I have the following...
|
by: Bjorn Sagbakken |
last post by:
Hello
In VS2005:
I am adding buttons and textboxes dynamically into a table, that also
dynamically expands.
So far, so good, actually very nice.
But I am having trouble starting the desired...
|
by: nse111 |
last post by:
Is it possible to have a Session variable as an array in PHP where,
that array gets values added to it dynamically?
Im trying to create a inquiry cart where the product ids of all the items...
|
by: amek000 |
last post by:
<script language="javascript">
function calcvaluesArr(){
var txts = document.getElementsByName('textfield23');
var aTotal=0;
for (var i = 0; i < txts.length; i++)
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
| |