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;
}
}