T
tbh
I'd like to create a generic method that returns a list of objects derived
from a class that "wraps" a guid.
public static List<ID> GetList<ID>(...) where ID : MyGuidWrapper {
...
}
however in the step(s) where I create one of my ID objects:
// this works, I guess because MyGuidWrapper (a real class) knows how to
instantiate itself from a system Guid
MyGuidWrapper ing = new MyGuidWrapper(dr.GetGuid(0));
// but this yields a run-time error (can't cast.)
ID id = (ID)ing;
// and this runs without error but afterwards id is null
ID id = ing as ID;
Am I trying to do something that is impossible in C# or have I just not
figured out how to spell it yet?
I also wonder if I can specify a constraint on the order of:
Where ID:
- can be converted to and from a guid, e.g.
- hast a method Guid ToGuid() and
- is "newable" from a Guid; quasi: new(Guid)
under "constraints" I've found a new constraint, but only a parameterless
one. and I haven't figured out how to spell this as an interface yet either.
Cheers,
Tim Hanson
from a class that "wraps" a guid.
public static List<ID> GetList<ID>(...) where ID : MyGuidWrapper {
...
}
however in the step(s) where I create one of my ID objects:
// this works, I guess because MyGuidWrapper (a real class) knows how to
instantiate itself from a system Guid
MyGuidWrapper ing = new MyGuidWrapper(dr.GetGuid(0));
// but this yields a run-time error (can't cast.)
ID id = (ID)ing;
// and this runs without error but afterwards id is null
ID id = ing as ID;
Am I trying to do something that is impossible in C# or have I just not
figured out how to spell it yet?
I also wonder if I can specify a constraint on the order of:
Where ID:
- can be converted to and from a guid, e.g.
- hast a method Guid ToGuid() and
- is "newable" from a Guid; quasi: new(Guid)
under "constraints" I've found a new constraint, but only a parameterless
one. and I haven't figured out how to spell this as an interface yet either.
Cheers,
Tim Hanson