Can an enum start empty and be added to on the fly? 15 16664
"apm" <Co*********@Ad sorptionProcess Modeling.com> wrote in message
news:wWe2f.9538 $U%5.5934@laker ead05... Can an enum start empty and be added to on the fly?
AFAIK, no.
"apm" <Co*********@Ad sorptionProcess Modeling.com> wrote in message
news:wWe2f.9538 $U%5.5934@laker ead05... 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.WriteLi ne(MyEnum.OPENE D.ToString());
Console.WriteLi ne(MyEnum.OPENE D.ToOrdinal().T oString());
Console.WriteLi ne(MyEnum.INVAL ID.ToString());
Console.WriteLi ne(MyEnum.INVAL ID.ToOrdinal(). ToString());
Console.WriteLi ne(MyEnum.CLOSE D.ToString());
Console.WriteLi ne(MyEnum.CLOSE D.ToOrdinal().T oString());
Console.ReadLin e();
}
}
Regards,
Jeff
*** Sent via Developersdex http://www.developersdex.com ***
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** ********@TK2MSF TNGP15.phx.gbl. .. "apm" <Co*********@Ad sorptionProcess Modeling.com> wrote in message news:wWe2f.9538 $U%5.5934@laker ead05... 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 "deserializ ed" (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******** ******@TK2MSFTN GP14.phx.gbl... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. .. "apm" <Co*********@Ad sorptionProcess Modeling.com> wrote in message news:wWe2f.9538 $U%5.5934@laker ead05... 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 "deserializ ed" (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(whic h 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******** ********@TK2MSF TNGP12.phx.gbl. .. "Mike Schilling" <ms************ *@hotmail.com> wrote in message news:uK******** ******@TK2MSFTN GP14.phx.gbl... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. .. "apm" <Co*********@Ad sorptionProcess Modeling.com> wrote in message news:wWe2f.9538 $U%5.5934@laker ead05... 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 "deserializ ed" (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(whic h 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*********@Ad sorptionProcess Modeling.com> wrote in message
news:dGE2f.1222 0$U%5.8789@lake read05... "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******** ********@tk2msf tngp13.phx.gbl. .. "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. "Mike Schilling" <ms************ *@hotmail.com> wrote in message news:uK******** ******@TK2MSFTN GP14.phx.gbl... "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"apm" <Co*********@Ad sorptionProcess Modeling.com> wrote in message news:wWe2f.9538 $U%5.5934@laker ead05... > 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 "deserializ ed" (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(whic h 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. 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 anyone knows please let me know....
Thanks,
|
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 want to get the notification
of the menu item click which is added dynamically. I want to put one common
routine where I can distinguish between all menu item clicks. Menu Items can
be two or hundred. So, how to make one handler that will be...
|
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 suggestions will be helpful.
Thanks
|
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 dynamically, for some of the inserted
controls.
The controls (e.g., textBoxes) get created correctly and viewstate is
maintained across postbacks, etc - BUT there is an issue with the validation
controls.
The validation controls, themselves are...
|
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 which I want to
fetch once the moment i start my application and store that in Enum.
Regards
Sudhakara.T.P.
| |
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. When the user clicks the "Add another email" it
will call a client side JavaScript function, add_email, which will
dynamically add a new set of controls to the webpage using the innerHTML
method. It appears to work perfectly fine in the browser. The...
|
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 as the value of innerHTML:
"<TABLE>
<TR>
<TD id=td6x vAlign=top align=right><IMG height=14 alt=Required
src=\"/images/ci/icons/required.gif\" width=7 border=0
vAlign=\"top\"><INPUT id=anchor6x width=0 size=10
|
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 subroutine on postback. To me
it seems like the button click event looks for a client script instead of
going to the aspx codepage and execute the sub there.
The same thing happens with textboxes, where I programatically add
|
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 that a customer inquires about gets stored in a session variable. how can I do this?
the ids can be sepperated by a delimeter dynamically. I just cant get this done. pls help if you know. thans in advance!
|
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++)
{
if (txts.value!="")
{
aTotal=eval(aTotal)+eval(txts.value);
}
|
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...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |