Examples

C1.cs
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02namespace Db4objects.Db4odoc.onstructors 03{ 04 class C1 05 { 06 private string s; 07 08 private C1(string s) 09 { 10 this.s=s; 11 } 12 13 override public string ToString() 14 { 15 return s; 16 } 17 } 18}

C1.vb
01' Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com 02Namespace Db4objects.Db4odoc.Constructors 03 Class C1 04 Private s As String 05 06 Private Sub New(ByVal s As String) 07 Me.s = s 08 End Sub 09 10 Public Overrides Function ToString() As String 11 Return s 12 End Function 13 End Class 14End Namespace

The above class is fine for use with and without callConstructors set.

C2.cs
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02using Db4objects.Db4o; 03 04namespace Db4objects.Db4odoc.onstructors 05{ 06 class C2 07 { 08 [Transient] private string _x; 09 private string _s; 10 11 private C2(string s) 12 { 13 _s=s; 14 _x="x"; 15 } 16 17 override public string ToString() 18 { 19 return _s+_x.Length; 20 } 21 } 22}

C2.vb
01' Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com 02Imports Db4objects.Db4o 03 04Namespace Db4objects.Db4odoc.Constructors 05 Class C2 06 <Transient()> Private x As String 07 Private s As String 08 09 Private Sub New(ByVal s As String) 10 Me.s = s 11 Me.x = "x" 12 End Sub 13 14 Public Overrides Function ToString() As String 15 Return s + x.Length.ToString 16 End Function 17 End Class 18End Namespace

The above C2 class needs to have callConstructors set to true. Otherwise, since transient members are not stored and the constructor code is not executed, toString() will potentially run into a NullPointerException on x.length().

C3.cs
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02namespace Db4objects.Db4odoc.onstructors 03{ 04 class C3 05 { 06 private string _s; 07 private int _i; 08 09 private C3(string s) 10 { 11 _s=s; 12 _i=s.Length; 13 } 14 15 override public string ToString() 16 { 17 return _s+_i; 18 } 19 } 20}

C3.vb
01' Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com 02Namespace Db4objects.Db4odoc.Constructors 03 Class C3 04 Private s As String 05 Private i As Integer 06 07 Private Sub New(ByVal s As String) 08 Me.s = s 09 Me.i = s.Length 10 End Sub 11 12 Public Overrides Function ToString() As String 13 Return s + i.ToString() 14 End Function 15 End Class 16End Namespace

The above C3 class needs to have callConstructors set to false (the default), since the (only) constructor will throw a NullPointerException when called with a null value.

C4.cs
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02using Db4objects.Db4o; 03 04namespace Db4objects.Db4odoc.onstructors 05{ 06 class C4 07 { 08 private string _s; 09 [Transient] private int _i; 10 11 private C4(string s) 12 { 13 _s=s; 14 _i=s.Length; 15 } 16 17 override public string ToString() 18 { 19 return _s+_i; 20 } 21 } 22}

C4.vb
01' Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com 02Imports Db4objects.Db4o 03 04Namespace Db4objects.Db4odoc.Constructors 05 Class C4 06 Private s As String 07 <Transient()> Private i As Integer 08 09 Private Sub New(ByVal s As String) 10 Me.s = s 11 Me.i = s.Length 12 End Sub 13 14 Public Overrides Function ToString() As String 15 Return s + i.ToString() 16 End Function 17 End Class 18End Namespace

This class cannot be cleanly reinstantiated by db4o: both approaches will fail, so one has to resort to configuring a translator.