01/* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com */ 02
using System; 03
04
namespace Db4objects.Db4odoc.onstructors 05
{ 06
class C1 07
{ 08
private String s; 09
10
private C1(String s) 11
{ 12
this.s=s; 13
} 14
15
override public String ToString() 16
{ 17
return s; 18
} 19
} 20
}
01' Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com 02
Imports System 03
04
Namespace Db4objects.Db4odoc.Constructors 05
Class C1 06
Private s As String 07
08
Private Sub New(ByVal s As String) 09
Me.s = s 10
End Sub 11
12
Public Overrides Function ToString() As String 13
Return s 14
End Function 15
End Class 16
End Namespace
The above class is fine for use with and without callConstructors set.
01/* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com */ 02
using System; 03
using Db4objects.Db4o; 04
05
namespace Db4objects.Db4odoc.onstructors 06
{ 07
class C2 08
{ 09
[Transient] private String x; 10
private String s; 11
12
private C2(String s) 13
{ 14
this.s=s; 15
this.x="x"; 16
} 17
18
override public String ToString() 19
{ 20
return s+x.Length; 21
} 22
} 23
}
01' Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com 02
Imports System 03
Imports Db4objects.Db4o 04
05
Namespace Db4objects.Db4odoc.Constructors 06
Class C2 07
<Transient()> Private x As String 08
Private s As String 09
10
Private Sub New(ByVal s As String) 11
Me.s = s 12
Me.x = "x" 13
End Sub 14
15
Public Overrides Function ToString() As String 16
Return s + x.Length.ToString 17
End Function 18
End Class 19
End 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().
01/* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com */ 02
using System; 03
04
namespace Db4objects.Db4odoc.onstructors 05
{ 06
class C3 07
{ 08
private String s; 09
private int i; 10
11
private C3(String s) 12
{ 13
this.s=s; 14
this.i=s.Length; 15
} 16
17
override public String ToString() 18
{ 19
return s+i; 20
} 21
} 22
}
01' Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com 02
Imports System 03
04
Namespace Db4objects.Db4odoc.Constructors 05
Class C3 06
Private s As String 07
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 18
End 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.
01/* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com */ 02
using System; 03
using Db4objects.Db4o; 04
05
namespace Db4objects.Db4odoc.onstructors 06
{ 07
class C4 08
{ 09
private String s; 10
[Transient] private int i; 11
12
private C4(String s) 13
{ 14
this.s=s; 15
this.i=s.Length; 16
} 17
18
override public String ToString() 19
{ 20
return s+i; 21
} 22
} 23
}
01' Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com 02
Imports System 03
Imports Db4objects.Db4o 04
05
Namespace Db4objects.Db4odoc.Constructors 06
Class C4 07
Private s As String 08
<Transient()> Private i As Integer 09
10
Private Sub New(ByVal s As String) 11
Me.s = s 12
Me.i = s.Length 13
End Sub 14
15
Public Overrides Function ToString() As String 16
Return s + i.ToString() 17
End Function 18
End Class 19
End Namespace
This class cannot be cleanly reinstantiated by db4o: Both approaches will fail, so one has to resort to configuring a translator.