Results 1 to 2 of 2

Thread: c# implicit type coversion for Ice generated classes/structs

  1. #1
    DeepDiver's Avatar
    DeepDiver is offline Registered User
    Name: Thomas Mueller
    Organization: Freelance Software Developer
    Project: Project depend on Customers
    Join Date
    Nov 2004
    Location
    Munich, Bavaria, Germany
    Posts
    105

    c# implicit type coversion for Ice generated classes/structs

    hi everybody,

    let's say we have following slice:
    Code:
    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:

    Code:
    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

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 03-02-2009, 02:28 AM
  2. Python: repr() of Slice structs/classes
    By cebix in forum Comments
    Replies: 2
    Last Post: 04-15-2008, 08:24 AM
  3. Feature Request: partial classes / structs in .net
    By programmerdad in forum Comments
    Replies: 2
    Last Post: 08-09-2006, 10:24 PM
  4. Latency: structs vs. classes
    By n2503v in forum Help Center
    Replies: 7
    Last Post: 10-09-2005, 12:08 AM
  5. C#: Attributes with Ice generated classes and structs
    By DeepDiver in forum Help Center
    Replies: 2
    Last Post: 07-23-2005, 02:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •