473,516 Members | 2,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enumerations and out of scope values

I have an enumeration of constants as follows.

public enum eDeviceErrors
{
NoError = 0,
ENOENT = 2,
EBADF = 9,
EACCES = 13,
EINVAL = 22,
Checksum = 40,
SeqNum = 41,
InvalidTour = 42,
CommandNotRecognized = 43,
FOPEN = 44,
LENGTH = 45,
TERMINATOR = 46,
FWRITE = 47,
FCLOSE = 48,
FGETC = 49,
InvalidCode = 100
}

If I read a byte from the comport and want to assign this byte to an
enumerated variable, yet catch the case where the value isn't within scope
without testing against each possible value, how do I do this please?
eg
eDeviceErrors Errors = MyComport.Read(1);
Nov 16 '05 #1
2 1404
You may use System.Enum.IsDefined:
if (! Enum.IsDefined(typeof(eDeviceErrors), value)
{
throw ...;
}
eDeviceErrors e = (eDeviceErrors) value;

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Claire" <as*******@ntlworld.com> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
I have an enumeration of constants as follows.

public enum eDeviceErrors
{
NoError = 0,
ENOENT = 2,
EBADF = 9,
EACCES = 13,
EINVAL = 22,
Checksum = 40,
SeqNum = 41,
InvalidTour = 42,
CommandNotRecognized = 43,
FOPEN = 44,
LENGTH = 45,
TERMINATOR = 46,
FWRITE = 47,
FCLOSE = 48,
FGETC = 49,
InvalidCode = 100
}

If I read a byte from the comport and want to assign this byte to an
enumerated variable, yet catch the case where the value isn't within scope
without testing against each possible value, how do I do this please?
eg
eDeviceErrors Errors = MyComport.Read(1);

Nov 16 '05 #2
That's great thanks Dennis
Nov 16 '05 #3

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

Similar topics

2
1696
by: Glenn | last post by:
I've been trying to generate enumerations with specific integer values using an XSD and xsd.exe. e.g public enum AccessSecurity { Normal = 1, Restricted = 100001 }
1
5601
by: Oleg Ogurok | last post by:
Hi all, I've added a new DataSet (xsd file) to my project in VS.NET 2003. There I create a simple type as an enumeration of values. <xs:simpleType name="MyCustomType"> <xs:restriction base="xs:string"> <xs:enumeration value="Apple" /> <xs:enumeration value="Orange" /> </xs:restriction>
4
3527
by: ChrisB | last post by:
Hello: I will be creating 50+ enumerations related to a large number of classes that span a number of namespaces. I was wondering if there are any "best practices" when defining enumerations. Should a single class be created that contains all of a solution's enumerations? Or should enumerations be defined directly in the files that...
0
1289
by: Ben Finney | last post by:
Howdy all, I've uploaded enum 0.3 to the Cheeseshop. <URL:http://cheeseshop.python.org/pypi/enum/> Enumerations are now sequences, iterable (as before) *and* indexable:: >>> from enum import Enum >>> Weekdays = Enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
27
2639
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to provide a "one obvious way" to do enumerations in Python. > >>> from enum import Enum > >>> day = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
77
3871
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the reStructuredText source as it is today. Please discuss it here so I can see what issues people may have.
6
3553
by: DippyDog | last post by:
This is an old old post that I'm referencing regarding what happens when you set an integer variable to Nothing. It gets set to zero, not "Nothing." http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/6732ea8e7016bd24/70608745c29d048b?lnk=gst&q=can%27t+set+enum+to+nothing#70608745c29d048b Just to expand...
0
7276
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...
0
7182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7581
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
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...
0
5714
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...
1
5110
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...
0
1624
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
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
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...

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.