Archived
This forum has been archived. Please start a new discussion on GitHub.
c# implicit type coversion for Ice generated classes/structs
hi everybody,
let's say we have following slice:
while working with c# i'd like to use System.DateTime.
so what would solve this problem is:
add implicit conversion operators to the generated class:
this works fine - but i don't like the idea of modifying generated code.
and this also doesn't work for sequence<IceDateTime> or IceDdateTime being a member of another class/struct.
so - let me know your ideas!
THX & CU Tom
let's say we have following slice:
class IceDateTime { long ticks };
while working with c# i'd like to use System.DateTime.
so what would solve this problem is:
add implicit conversion operators to the generated class:
public static implicit operator IceDateTime(System.DateTime val) { IceDateTime rtn = new IceDateTime(); rtn.ticks = val.Ticks; return rtn; } public static implicit operator System.DateTime(IceDateTime val) { return new DateTime( val.ticks ); }
this works fine - but i don't like the idea of modifying generated code.
and this also doesn't work for sequence<IceDateTime> or IceDdateTime being a member of another class/struct.
so - let me know your ideas!
THX & CU Tom
0
Comments
-
I'm afraid I don't have better ideas and as you mentioned it's not a good idea to modify the generated code. Also, note that using a class just to encapsulate a long value is a bit of overkill. Marshalling classes is much more expensive than just marshalling long values. In this case, the easiest is to simply pass the Ticks attribute of the System.DateTime object .
Benoit.0