H
Hung Jung Lu
Hi,
I just downloaded rotor and gyro and am playing a bit with generics. I
enclose a sample program. My question is, according to the language
spec (http://msdn.microsoft.com/vcsharp/team/language/default.aspx, C#
2.0 Specification), a syntax like:
public class MathEngine<T> where T: IHasX, IHasY {
…
}
should be valid. Yet, the rotor+gyro compiler complains. I have
attempted also
public class MathEngine<T> where T: IHasX, T: IHasY {
…
}
but it seems that it only picks up the last part, namely, only IHasY.
I know rotor+gyro are kind of experimental, but still, I'd like to
make sure I am not missing out obvious explanations. Are these
problems just bugs?
Regards,
Hung Jung
using System;
public interface IHasX {
int x {get;set;}
}
public interface IHasY {
int y {get;set;}
}
public class MathEngine<T> where T: IHasX, IHasY {
public void incX(T me) {
int x;
x = me.x;
x += 1;
me.x = x;
}
public void incY(T me) {
int y;
y = me.y;
y += 1;
me.y = y;
}
}
public class A: IHasX, IHasY {
int _x;
int _y;
public MathEngine<A> math;
public A() {
_x = 2;
_y = 3;
math = new MathEngine<A>();
}
public int x {
get {return _x;}
set {_x = value;}
}
public int y {
get {return _y;}
set {_y = value;}
}
public void calc() {
math.incX(this);
}
}
class MainApp {
public static void Main() {
A a;
a = new A();
a.calc();
Console.WriteLine("Values = {0}", a.x);
}
}
I just downloaded rotor and gyro and am playing a bit with generics. I
enclose a sample program. My question is, according to the language
spec (http://msdn.microsoft.com/vcsharp/team/language/default.aspx, C#
2.0 Specification), a syntax like:
public class MathEngine<T> where T: IHasX, IHasY {
…
}
should be valid. Yet, the rotor+gyro compiler complains. I have
attempted also
public class MathEngine<T> where T: IHasX, T: IHasY {
…
}
but it seems that it only picks up the last part, namely, only IHasY.
I know rotor+gyro are kind of experimental, but still, I'd like to
make sure I am not missing out obvious explanations. Are these
problems just bugs?
Regards,
Hung Jung
using System;
public interface IHasX {
int x {get;set;}
}
public interface IHasY {
int y {get;set;}
}
public class MathEngine<T> where T: IHasX, IHasY {
public void incX(T me) {
int x;
x = me.x;
x += 1;
me.x = x;
}
public void incY(T me) {
int y;
y = me.y;
y += 1;
me.y = y;
}
}
public class A: IHasX, IHasY {
int _x;
int _y;
public MathEngine<A> math;
public A() {
_x = 2;
_y = 3;
math = new MathEngine<A>();
}
public int x {
get {return _x;}
set {_x = value;}
}
public int y {
get {return _y;}
set {_y = value;}
}
public void calc() {
math.incX(this);
}
}
class MainApp {
public static void Main() {
A a;
a = new A();
a.calc();
Console.WriteLine("Values = {0}", a.x);
}
}