473,623 Members | 3,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enum Property with Interface

What do I to declare the header of a Property in an Interface, and should this property return a generic Enum?

Example:

public interface IMetric
{
Enum Unit { get;}
}

public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}

private EnumTeste _Unit;

public EnumTeste Unit
{
get
{
return _Unit;
}
}
}
Aug 17 '06 #1
2 20137
Cristiano de Pádua Milagres Oliveira wrote:
What do I to declare the header of a Property in an Interface, and
should this property return a generic Enum?

Example:
public interface IMetric
{
Enum Unit { get;}
}

public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTeste _Unit;
public EnumTeste Unit
{
get
{
return _Unit;
}
}
}
This compiles and works:

public interface IMetric
{
Enum Unit { get;}
}
public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public Enum Unit{ get{ return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumT est ttt = (ClassTest.Enum Test)tt.Unit;
}
}

Or using generics:

public interface IMetric<T>
{
T Unit { get;}
}
public class ClassTest : IMetric<ClassTe st.EnumTest>
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public EnumTest Unit { get { return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumT est ttt = tt.Unit;
}
}

Aug 17 '06 #2
Thanks, the change was small but the help was large!

"Andreas Mueller" <me@privacy.net escreveu na mensagem
news:4k******** ****@individual .net...
Cristiano de Pádua Milagres Oliveira wrote:
>What do I to declare the header of a Property in an Interface, and should
this property return a generic Enum?

Example:
public interface IMetric
{
Enum Unit { get;}
}

public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTeste _Unit;
public EnumTeste Unit
{
get
{
return _Unit;
}
}
}

This compiles and works:

public interface IMetric
{
Enum Unit { get;}
}
public class ClassTest : IMetric
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public Enum Unit{ get{ return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumT est ttt = (ClassTest.Enum Test)tt.Unit;
}
}

Or using generics:

public interface IMetric<T>
{
T Unit { get;}
}
public class ClassTest : IMetric<ClassTe st.EnumTest>
{
public enum EnumTest
{
T1 = 0,
T2 = 1
}
private EnumTest _Unit = EnumTest.T2;
public EnumTest Unit { get { return _Unit; } }
}

class Program
{
static void Main(string[] args)
{

ClassTest tt = new ClassTest();
ClassTest.EnumT est ttt = tt.Unit;
}
}

Aug 17 '06 #3

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

Similar topics

0
340
by: Kakaiya | last post by:
UCTest.vb ---------- Imports System.ComponentModel Public Class UCTest Inherits System.Windows.Forms.UserControl #Region " Windows Form Designer generated code "
2
5484
by: Kimmo Laine | last post by:
Hello, is there a way to do this VB6 code in C#: Enum MyEnumA A1 A2 End Enum Enum MyEnumB
6
4815
by: Bob | last post by:
It should be simple, but I'm stuck on this one... how do you return a value for an enum property type? TIA, Bob
1
3352
by: Jenny Fletcher | last post by:
I am trying to dynamically invoke a property of enumeration type but I can't find a way to get it to work. This is my code which works fine until I call InvokeMember and I get an ArgumentException. I've tried various combinations of parameters in my call to InvokeMember but can't find anything that does the job. Any help would be appreciated. Jenny Dim arrObj(0) As Object Dim objPInfo As PropertyInfo =...
2
3752
by: Lance | last post by:
Can somebody tell me how to allow the user to check and uncheck Enum flags in a PropertyGrid. In other words, how to display a drop down box that contains a check next to each enum value as well as a None button at the bottom when the user selects the property in a PropertyGrid Thank you Lance
3
1065
by: Frank | last post by:
Hello, question about the values for a property. I have a class with an enum and property: classA public enum x as short a b c end enum
3
1479
by: Alan | last post by:
Hi, is it possible to create a project that can offer different members of a Public Enum according to a condition ? I mean, Project A has a public enum. Project B & C access A's enum. However B should see some elements of the enum while C should see others... Is this achievable ??
2
1758
by: fred | last post by:
Hi, Why should I do a cast (IOfferSetter) in the constructor of the Test class? Thanks. Fred public interface IOfferSetter { object Offer { set;} } public class OfferCtx {
3
3745
by: Andrew Bainbridge | last post by:
Hi, I'm converting some code over from vb.net to c# and have the following issue. In VB you can have enum's within an interface. i.e. Public Interface Class1 Enum ColorType Black Red
0
8163
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
8665
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...
0
8607
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8319
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
7140
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
6104
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
5560
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();...
1
2596
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
1772
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.