.NET Example Class

This topic applies to .NET version only. 

For this example we'll be using a hypothetical LocalizedItemList class which binds together culture
information with a list of items.

System.Globalization.CultureInfo is particularly interesting because it internally holds a native pointer
to a system structure which in turn cannot be cleanly stored by db4o.

 


We'll be using this code to store and retrieve and instance of this class with different configuration
settings:

 

 

Using The Constructor 

 


At storage time, db4o tests the only available constructor with null arguments and runs into a
NullPointerException, so it refuses to accept our object.
(Note that this test only occurs when configured with exceptionsOnNotStorable - otherwise db4o will
silently fail when trying to reinstantiate the object.)

Bypassing The Constructor 

 


This still does not work for our case because the native pointer will definitely be invalid. In fact this
example crashes the Common Language Runtime.

In order to solve the problem we will need to use db4o Translators