Actually, I'm just using MemoryStream and BinaryFormatter to serialize the object - so this requires the object be marked with SerializableAttribute, client can customize which fields will not be serialized with NonSerializableAttribute. I'm not sure if that addresses your concerns - but the reason I chose this was because I never could get BerkeleyDb to store an instance of a class when I Marshal::StructureToPtr, and then get that class rehydrated with Marshal::PtrToStructure (since Berkeley Db ultimately takes void* as input and returns void* as output).
It feels as if I'm defeating a purpose using serialization, but I'm just experimenting at the moment and will see how it goes when it comes to getting Berkeley Db cursors. My thoughts are that Berkeley Db stores data in it's native format, and when the application requests data it sends this data in void* and leaves it up to the application to rehydrate the data - so I send it byte arrays, it converts to void* and stores, I request data - it sends me a void* and I deserialize that to a byte[] to which the BinaryFormatter will deserialize. The generic Parameter class would deserialize to type T. Ron ----- Original Message ----- From: "Stoyan Damov" <[EMAIL PROTECTED]> To: <ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> Sent: Thursday, March 16, 2006 3:45 PM Subject: Re: [ADVANCED-DOTNET] Store generic type as fields in class Ron, Hardcoding the serialization is not a good thing IMO. If this wrapper will only be used by you, that's probably OK, but if you intend to get the library out (w/ whatever license) it's not good, you need to provide some way for the library user to serialize his types (e.g. I may have a type w/ 30 fields calculated from 1 and I might want to serialize only that field). The simpliest thing you can do is to have a ByteArrayParameter, taking byte[], and derive BerkeleyParameter<> from it, which initializes the base class w/ the binary-serialized key and data (then the user will be able to pass instances of ByteArrayParameter directly). On 3/16/06, RYoung <[EMAIL PROTECTED]> wrote:
Ahh. I'm actually getting into writing a C++/CLI wrapper over the BerkeleyDb C++ API. The "BerkeleyParameter" is what I hope to be a way of passing a managed object to the wrapper, so that it's "value" can be marshaled to void* (and back out to the managed type) for use in the Dbt class. I'd like the client to be able to do this: Person p = new Person(); p.FirstName = ... p.LastName =.. Guid personKey = Guid::NewGuid(); BerkeleyParameter<Guid> key = new BerkeleyParameter<Guid>(personKey); BerkeleyParameter<Person> data = new BerkleyParameter<Person>(data); BerkeleyCommand<Guid, Person> cmd = new BerkeleyCommand<Guid, Person>(CommandType.Insert); cmd.AddParameters(key, data); cmd.Execute(); The BerkeleyParameter uses binary serialization to convert it's "value" (a managed type) to byte[], which the Command will then convert to void*. Command will also retrive a void* from the BDb API, convert it to byte[] - pass it to Parameter for deserialization to the managed type. Ron
Cheers, Stoyan =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com