Home Help Center

c# implicit type coversion for Ice generated classes/structs

DeepDiverDeepDiver Member Thomas MuellerOrganization: Freelance Software DeveloperProject: Project depend on Customers ✭✭✭
hi everybody,

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


  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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 :).

Sign In or Register to comment.