I have an enum defined as
public enum velocityUom
{ /// <remarks/>
[System.Xml.Seri alization.XmlEn umAttribute("m/s")]
ms,
/// <remarks/>
[System.Xml.Seri alization.XmlEn umAttribute("cm/a")]
cma,
...
}
This class was generated by xsd.exe, from a schema like
<xsd:simpleTy pe name="velocityU om">
<xsd:enumeratio n value="m/s"/>
<xsd:enumeratio n value="cm/a"/>
....
</xsd:restriction >
</xsd:simpleType>
I would like to retrieve the XmlEnumAttribut e values for this Enum so that I
can create a combo box with values like "m/s", "cm/a", ... so that I don't
have to hard-code the XML-enum values in my code.
Is there any way to do this? the MSDN examples are only to add extra enum
values for a class and Enum.GetNames() just retrieves "ms", "cma", ...
Thanks,
Edward Clements 5 6632
I forgot to mention that I use .Net v2.0
Edward
"Edward Clements" wrote: I have an enum defined as public enum velocityUom { /// <remarks/> [System.Xml.Seri alization.XmlEn umAttribute("m/s")] ms,
/// <remarks/> [System.Xml.Seri alization.XmlEn umAttribute("cm/a")] cma, ... }
This class was generated by xsd.exe, from a schema like <xsd:simpleTy pe name="velocityU om"> <xsd:enumeratio n value="m/s"/> <xsd:enumeratio n value="cm/a"/> ... </xsd:restriction > </xsd:simpleType>
I would like to retrieve the XmlEnumAttribut e values for this Enum so that I can create a combo box with values like "m/s", "cm/a", ... so that I don't have to hard-code the XML-enum values in my code.
Is there any way to do this? the MSDN examples are only to add extra enum values for a class and Enum.GetNames() just retrieves "ms", "cma", ...
Thanks,
Edward Clements
A bit of reflection can do this:
Type enumType = typeof(velocity Uom);
foreach (FieldInfo fi in enumType.GetFie lds())
{
object[] attrs = fi.GetCustomAtt ributes(typeof( XmlEnumAttribut e), false);
if (attrs.Length > 0)
{
Console.WriteLi ne(((XmlEnumAtt ribute)attrs[0]).Name);
}
}
--
Oleg Tkachenko [XML MVP, MCAD] http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Edward Clements wrote: I have an enum defined as public enum velocityUom { /// <remarks/> [System.Xml.Seri alization.XmlEn umAttribute("m/s")] ms,
/// <remarks/> [System.Xml.Seri alization.XmlEn umAttribute("cm/a")] cma, ... }
This class was generated by xsd.exe, from a schema like <xsd:simpleTy pe name="velocityU om"> <xsd:enumeratio n value="m/s"/> <xsd:enumeratio n value="cm/a"/> ... </xsd:restriction > </xsd:simpleType>
I would like to retrieve the XmlEnumAttribut e values for this Enum so that I can create a combo box with values like "m/s", "cm/a", ... so that I don't have to hard-code the XML-enum values in my code.
Is there any way to do this? the MSDN examples are only to add extra enum values for a class and Enum.GetNames() just retrieves "ms", "cma", ...
Thanks,
Edward Clements
Oleg,
Thanks for the idea and especially for the code sample; it works quite well!
Only, I couldn't find any way to connect the enumeration (int) value to the
XML string value -- for example, if the user selects "cm/a" from the combo
box, how would the program know that it should use velocityUom.ms? I could
use just a counter in the foreach() loop, but
a) would that work ok?
b) that would not take care of the situation where the enum values are not
sequential starting from zero
Could you please help?
Thanks,
Edward Clements
"Oleg Tkachenko [MVP]" wrote: A bit of reflection can do this:
Type enumType = typeof(velocity Uom); foreach (FieldInfo fi in enumType.GetFie lds()) { object[] attrs = fi.GetCustomAtt ributes(typeof( XmlEnumAttribut e), false); if (attrs.Length > 0) { Console.WriteLi ne(((XmlEnumAtt ribute)attrs[0]).Name); } }
-- Oleg Tkachenko [XML MVP, MCAD] http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Edward Clements wrote: I have an enum defined as public enum velocityUom { /// <remarks/> [System.Xml.Seri alization.XmlEn umAttribute("m/s")] ms,
/// <remarks/> [System.Xml.Seri alization.XmlEn umAttribute("cm/a")] cma, ... }
This class was generated by xsd.exe, from a schema like <xsd:simpleTy pe name="velocityU om"> <xsd:enumeratio n value="m/s"/> <xsd:enumeratio n value="cm/a"/> ... </xsd:restriction > </xsd:simpleType>
I would like to retrieve the XmlEnumAttribut e values for this Enum so that I can create a combo box with values like "m/s", "cm/a", ... so that I don't have to hard-code the XML-enum values in my code.
Is there any way to do this? the MSDN examples are only to add extra enum values for a class and Enum.GetNames() just retrieves "ms", "cma", ...
Thanks,
Edward Clements
Edward Clements wrote: Only, I couldn't find any way to connect the enumeration (int) value to the XML string value -- for example, if the user selects "cm/a" from the combo box, how would the program know that it should use velocityUom.ms? I could use just a counter in the foreach() loop, but a) would that work ok? b) that would not take care of the situation where the enum values are not sequential starting from zero
Well, combobox items have both text and value behind. That's your
responsibility to make sure that with "cm/a" item in a combobox has
velocityUom.ms value.
--
Oleg Tkachenko [XML MVP, MCAD] http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Oleg,
Sorry, I didn't make myself clear -- what I'd like to know is, while looping
through the FieldInfo to get the string XMLEnumAttribut es, whether it is
possible to retrieve the corresponding enumerated (int) value for each
string; I could use just a counter in the foreach() loop, but
a) would that work ok?
b) that would not take care of the situation where the enum values are not
sequential starting from zero
Thanks,
Edward Clements
"Oleg Tkachenko [MVP]" wrote: Well, combobox items have both text and value behind. That's your responsibility to make sure that with "cm/a" item in a combobox has velocityUom.ms value.
-- Oleg Tkachenko [XML MVP, MCAD] http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: antonyliu2002 |
last post by:
This message was originally a follow-up in a thread, but it went
ignored and I do want some help so I am initiating it as a new topic.
After Patrick and Karl showed me some examples, I was trying to retain
user data across multiple pages using the Context facility.
On page1.aspx, I have
Page1 | Page2 |
|
by: Ihsan_al-shorafa |
last post by:
We are trying to put together an exception handling framework and were
wondering if you can help us out with a problem that we ran into...
Q: Is there a way, through reflection or any other mechanism, to retrieve
runtime values that were passed into a method that threw an exception?
Basically, I would like our base exception class to traverse the
stackframe and to gather all values that were passed to method(s) on the
stack. Currently, I...
|
by: Ken Varn |
last post by:
I am sure this has been asked before, but I was wondering is there some way
of getting the data values out of a DataGrid Item without having to resort
to indexing into the item's cell collection?
I would like to be able to retrieve row column values by DataRowViw object,
rather than by index. I know that this can by done by using the DataItem
when the DataGrid is initially bound, but unless you bind on every postback,
this will not work...
|
by: Captain Dondo |
last post by:
I am not really experienced in Javascript so bear with me....
I am working with an embedded platform; no mouse, no keyboard. Just up,
down, left, right keys and +/- keys for incrementing/decrementing the
vaules in the form.
So my website consists of forms... Each form has a number of columns
and rows. I am generating each page using a php script and some
templates. Because the exact layout of each page can change based on
customer...
|
by: Randy Williams |
last post by:
Hi All,
I have an VS.NET 2003 app which will be processing XML files, some of which
will have empty elements (for example, <Item />). I have an XSD file which
should supply default values, but I am not able to read these plugged in
value using an XMLDocument object. The validation is working fine--it's just
not providing any default values.
Has anybody tried this? Am I must be missing something? This is one of
those that "should...
| |
by: jupitermoonbeam |
last post by:
Hi,
I wondered if anyone can help. I have scowered the web and found
absolutely nothing that relates to my particular problem and I am
pulling my hair out.
Basically, I have a scenario where I need to retrieve the previous
value of a control (a text box) from the ViewState and compare it
directly with the new value. I know there is the OnChange events etc.
etc. but for this particular scenario the OnChange event doesn't always
|
by: mickey22 |
last post by:
Hi all,
I have a txt file in the following format and have to retrieve the values when I give the key. For example:
(key) (value)
File = c:/a.hdr
Range = 10
Reference Value=100
This table is initially stored as file.txt.So initially I have to read this file.txt and I have to retrieve the values of each key.Key and value are separated by " =" operator.
|
by: Smartpriya |
last post by:
Hello,
I am doing project in Swing and Access. I have some Tables in database.. Now I need to retrive some values from it and put in Hashmap.
For ex: I have 3 tables like Node, Card, Line.
Node table contains Node name, Node id, etc..
Card table contains Node id, Card Type..
Line table contains Node id, Line Type..
Now i want values from fields Node name,Card Type, Line Type and to be put in Hashmap..so that based...
|
by: fahad77 |
last post by:
I created a class out of .xsd. Now I am generating a new xml file and trying to add "Notice" as an element with an attribute of Index="001". I'm trying to get to value XmlEnumAttribute("0001"). This is how my code looks like:
*************************Class*********************************
public partial class Notice {
private NoticeIndex indexField;
public Notice() {
this.indexField = NoticeIndex.Item0001;...
|
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: 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...
| |
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,...
|
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: 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.
| |