Re: Reflection and order of the fields
From: Ignacio Machin \( .NET/ C# MVP \) ("Ignacio)
Date: 03/08/04
- Next message: Jon: "RE: Simple Grid of Strings"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Reflection and order of the fields"
- In reply to: Frank D Lombardo: "Re: Reflection and order of the fields"
- Next in thread: Jon Skeet [C# MVP]: "Re: Reflection and order of the fields"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 8 Mar 2004 14:45:27 -0500
Hi frank,
AFAIK the CF does not support serialization, therefore you will have to
implement it by your own. An idea that comes to my head is declaring an
interface ( or a base class with a virtual method ) with a method that makes
a byte array with all what is needed to recreate the object in the other
end, then you can easily send it through the serial port, now as the exact
type of the object is not know you will need a kind of command ID to
determine the type of the object , and the size of the data stream
following, the stream can looks like:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----
| CommandID | object's data size | object data
.................................| CommandID| CommandID | object's data
size | object data .................................| ....
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----
You then can do something like this in the other end:
Command nextCommand = CommandFactory.CreateCommand(
ComHandler.ReadCommandId( ) );
byte[] commanddata = ComHandler.ReadByteArray( ComHandler.ReadDataSize() );
nextCommand.Deserialize( commanddata );
where ComHandler is a class or instance that read from the COM , it has
method like ReadCommandId() to read the next byte(s) needed to identify a
command .
You should also use an object factory to centralize and decouple the
creation of commands.
and it;s the responsability of the command itself to be able to recreate it
self from a byte[].
Hope this help,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Frank D Lombardo" <Frank@NoSpam.com> wrote in message news:OWipPpTBEHA.464@TK2MSFTNGP11.phx.gbl... > I guess I didn't tell you all of the requirements. The device at the other > end is an instrument I am trying to control. My code needs to run on both > the full framework and the compact framework. The objects I want to send > are command objects that have different data fields depending on the nature > of the command. > > Because of my specific serialization requirements, I was hoping to write my > own generic command serializer that would use reflection to determine the > run-time data fields of the command and send them over the wire. I'm just > not sure if I can rely on the declarative order of the fields being the > order that they are returned from GetFields(). > > -- > Frank D. Lombardo > Turning Point Technology, Inc. > Frank_AT_TurningPointOnline_DOT_com > > > > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in > message news:%233PBFgTBEHA.892@tk2msftngp13.phx.gbl... > > Frank, > > > > I am curious, if you are sending an object over the wire, then why not > > just use serialization (assuming that .NET is on the other side of the > > wire). > > > > The order of the fields is not guaranteed. Some reasonable > assumptions > > would be to get them in declarative order, and alphabetical, but I am not > > sure. If you need a specific order, I would recommend getting the > specific > > fields and then ordering them yourself. > > > > Hope this helps. > > > > > > -- > > - Nicholas Paldino [.NET/C# MVP] > > - mvp@spam.guard.caspershouse.com > > > > "Frank D Lombardo" <Frank@NoSpam.com> wrote in message > > news:O8nyEXTBEHA.1548@TK2MSFTNGP12.phx.gbl... > > > I am attempting to use Reflection to send an object over a serial port. > I > > > won't know the exact type of the object until run-time. If I call > > > GetFields(), is there any guarantee on the order the fields are > returned? > > > Would it help if I used a struct instead of a class? I need to send the > > > fields in a known and consistent order. I would also like this code to > > work > > > on the Compact Framework. > > > > > > > > > Thanks, > > > -- > > > Frank D. Lombardo > > > Turning Point Technology, Inc. > > > Frank_AT_TurningPointOnline_DOT_com > > > > > > > > > > > > > > > > > >
- Next message: Jon: "RE: Simple Grid of Strings"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Reflection and order of the fields"
- In reply to: Frank D Lombardo: "Re: Reflection and order of the fields"
- Next in thread: Jon Skeet [C# MVP]: "Re: Reflection and order of the fields"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|