Using Attributes

This topic applies to .NET version only

.NET Attributes provide the means for a developer to add meta-data that describes, or annotates specific elements of code such as classes, methods, properties, etc. At compile time the resulting metadata is placed into the Portable Executable (PE)file along with the Microsoft Intermediate Language (MSIL). Once metadata is in the PE other .NET programs may access it using the .NET Reflection API.

Attributes can be used to document classes at design time, specify runtime information (such as the name of an XML field to be used when serializing information from the class), and even dictate runtime behavior (such as whether the class should automatically participate in a transaction).

You can use attributes with db4o to configure how db4o will process your classes. At present we provide only one attribute:

[Indexed]

This attribute can be applied to class fields

Car.cs
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02using Db4objects.Db4o.Config.Attributes; 03 04namespace Db4objects.Db4odoc.Attributes 05{ 06 public class Car 07 { 08 [Indexed] 09 private string _model; 10 private int _year; 11 } 12}

Car.vb
1' Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com 2Imports Db4objects.Db4o 3 4Namespace Db4objects.Db4odoc.Attributes 5 Public Class Car 6 <Config.Attributes.Indexed()> Private _model As String 7 Private _year As Integer 8 End Class 9End Namespace


and its functionality is equivalent to the db4o configuration setting:

Db4o.Configure().ObjectClass(clazz).ObjectField("fieldName").Indexed(true)