473,657 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do an enumeration in an interface?

I have a situation where I have to combine an enumerated value with an
interface. How can this be done?

namespace Stuff
{
public interface IThing
{
// This doesn't work, of course...
public enum EnumeratedStuff
{
None, First, Second
}

bool SomeMethod();
}
}

namespace Stuff
{
public class Thing : IThing
{
// Implement the enumerated EnumeratedStuff .

bool SomeMethod()
{
return true;
}
}
}
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm
Aug 21 '07 #1
3 1290
Richard Lewis Haggard wrote:
I have a situation where I have to combine an enumerated value with an
interface. How can this be done?

namespace Stuff
{
public interface IThing
{
// This doesn't work, of course...
public enum EnumeratedStuff
{
None, First, Second
}

bool SomeMethod();
}
}

namespace Stuff
{
public class Thing : IThing
{
// Implement the enumerated EnumeratedStuff .

bool SomeMethod()
{
return true;
}
}
}
Do you mean something like this:

namespace Stuff
{
public interface IThing
{
bool SomeMethod();
EnumeratedStuff EnumStuff{ get;set; }
}

public enum EnumeratedStuff
{
None, First, Second
}
}

namespace Stuff
{
public class Thing : IThing
{
private EnumeratedStuff es = EnumeratedStuff .None;

public bool SomeMethod()
{
return true;
}

public EnumeratedStuff EnumStuff
{
get { return this.es; }
set { this.es = value; }
}
}
}
--
Tom Porterfield
Aug 21 '07 #2
Richard,

You can't do that. The enumeration has to be defined outside of the
interface, and you can't declare that the interface has to declare an
enumeration type with that name.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Richard Lewis Haggard" <HaggardAtWorld DotStdDotComwro te in message
news:eP******** ******@TK2MSFTN GP04.phx.gbl...
>I have a situation where I have to combine an enumerated value with an
interface. How can this be done?

namespace Stuff
{
public interface IThing
{
// This doesn't work, of course...
public enum EnumeratedStuff
{
None, First, Second
}

bool SomeMethod();
}
}

namespace Stuff
{
public class Thing : IThing
{
// Implement the enumerated EnumeratedStuff .

bool SomeMethod()
{
return true;
}
}
}
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm


Aug 21 '07 #3
Greatly appreciated. Your response told me exactly what I needed to know.
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm

"Tom Porterfield" <tp******@mvps. orgwrote in message
news:%2******** **********@TK2M SFTNGP03.phx.gb l...
Richard Lewis Haggard wrote:
>I have a situation where I have to combine an enumerated value with an
interface. How can this be done?

namespace Stuff
{
public interface IThing
{
// This doesn't work, of course...
public enum EnumeratedStuff
{
None, First, Second
}

bool SomeMethod();
}
}

namespace Stuff
{
public class Thing : IThing
{
// Implement the enumerated EnumeratedStuff .

bool SomeMethod()
{
return true;
}
}
}

Do you mean something like this:

namespace Stuff
{
public interface IThing
{
bool SomeMethod();
EnumeratedStuff EnumStuff{ get;set; }
}

public enum EnumeratedStuff
{
None, First, Second
}
}

namespace Stuff
{
public class Thing : IThing
{
private EnumeratedStuff es = EnumeratedStuff .None;

public bool SomeMethod()
{
return true;
}

public EnumeratedStuff EnumStuff
{
get { return this.es; }
set { this.es = value; }
}
}
}
--
Tom Porterfield

Aug 21 '07 #4

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

Similar topics

1
12628
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="red"/> <xsd:enumeration value="yellow"/> <xsd:enumeration value="blue"/> </xsd:simpleType>
0
1325
by: Brian Riis | last post by:
This all pertains to the above mentioned article. Anyone want to read it (it's rather neat, actually), here's the address: http://www.cuj.com/documents/s=8205/cujweb0305meynard/ Anyway, I was trying to work my way through the idea of the class, especially the one, that uses a template parameter for the enumeration value, in the hopes of getting an enum that enumerated through std::strings. The whole idea is to keep a base class with...
1
3356
by: Max Akbar | last post by:
Hi all, I am trying to enumerate the elements of a Compound storage file and I get an error (System.NullReferenceException) when I execute the "EnumElements" of the "UCOMIStorage". I can open the Compound file just fine just can't enumerate it's elements. Am I declaring something incorrectly? Sample Code: // Declaration of UCOMIStorage interface UCOMIStorage {
6
3527
by: Jamie Winder via .NET 247 | last post by:
Is it possible to iterate through all of the possible values of an enumeration? (with foreach, maybe?) What I need to do is fill a ComboBox with all possible values for an enumeration. e.g foreach ( in ) { comboBox1.Items.Add (value.ToString ("G"); }
4
5658
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation" for a second if you don't mind). However, it existed within intuitive language semantics, whereas the new "yield" keyword, while highly convenient, is also one of the most gross warping of language concepts to date... public IEnumerator...
2
5783
by: Jayme Pechan | last post by:
Is there a simple way to return a COM enumeration interface from .NET? I am porting a C++ COM Object that has an enumeration interface containing the DISPID_NEWENUM and DISPID_VALUE properties and the count property and need to create the equivilant in C#. I'm hoping I can just return an array list or something but something tells me it isn't that easy. Any thoughts on the proper way to do this in C#? Thanks. Jayme
3
2539
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string"> <xs:enumeration value="Mon"/> <xs:enumeration value="Tue"/> <xs:enumeration value="Wed"/>
0
500
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
0
3995
by: Christian Gosselin | last post by:
The problem: We have an interface (EnumInterface), an enumeration container (EnumContainer) and an enumeration type (TheEnum). We can set the EnumContainer through the EnumInterface. However when we retrieve the EnumContainer from the EnumInterface, the TheEnum within the EnumContainer is null (Assert.IsNotNull(enumService.getEnumContainer().anEnum); throws an exception). Any reason why C# can't retrieve the enum value ?
0
8323
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
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
8513
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
8613
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
7351
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
6176
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.