November 4, 2002

Object-Relational Mapping – Taking the Horror Out of Data Access

Object-Relational Mapping – Taking the Horror Out of Data Access 1. Horror stories and the object data divide Let’s face it, the world is getting more and more OO, but we are still pretty happy with our relational databases. In fact the RDBMS is the foundation upon which basically all

FilterByType – filtering the results of Type.FindMembers by thier return type

‘ Accept only properties and methods whose return value matches’ the Type passed as the second argument.’ Note: it requires Imports System.ReflectionFunction FilterByType(ByVal m As MemberInfo, ByVal filterCriteria As Object) As _ Boolean If m.MemberType = MemberTypes.Property Then ‘ If it is a property, cast MemberInfo to PropertyInfo. Dim pi

FilterByName – filtering by name the results of Type.FindMembers

‘ This filtering function returns True if the member name ‘ begins with the character passed as its second argument.’ Note: it requires Imports System.ReflectionFunction FilterByName(ByVal m As MemberInfo, ByVal filterCriteria As Object) As _ Boolean If m.Name.StartsWith(filterCriteria.ToString) Then Return True End IfEnd Function’ EXAMPLE:’ Get a reference to the

A command-line Object Browser that uses Reflection

‘ This code is taken from Francesco Balena’s’ “Programming Microsoft Visual Basic .NET” – MS Press 2002, ISBN 0735613753′ You can read a free chapter of the book at ‘ http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=101000Imports System.ReflectionModule MainModule Sub Main() ‘ Get command-line arguments. Dim args() As String = Environment.GetCommandLineArgs() Dim cmd As String =

Set up event handlers through reflection

Reflection makes it easy to invoke a method (or assign a field or aproperty) by its name. For example, suppose you have the following classes: Class Person Event PropertyChanged(ByVal propertyName As String, ByVal newValue As Object) Dim m_Name As String Property Name() As String Get Return m_Name End Get Set(ByVal