Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / Visual Basic

Using Reflection to Bind Object Data to Data Sources

Rate me:
Please Sign up or sign in to vote.
4.54/5 (16 votes)
26 May 20059 min read 69.6K   564   55  
This article describes classes that can be used to update data sources with object data via reflection.
Imports System.Reflection

#Region " Copyright Notice: "

'Copyright 2005 Front End Software, Joe Cleland
'-----------------------------------------------
'You have permission to use/distribute this software as long as this copyright
'notice is included.
'
'By using this software you agree that you are using it "AS-IS".
'There is No warranty for the maintenance or performance of this software.
'You shall not hold Front End Software, Joe Cleland or any affiliations
'responsible for any loss or damage you may incur by using this software.

#End Region

Namespace Data.Bind

#Region " DataSourceBinder Class:"



    '#########################################################################
    '#########################################################################
    '
    '   DataSourceBinder Class:
    '   -----------------------
    ''' <summary>
    ''' Use the methods of the DataSourceBinder class to collect object
    ''' values for updating to a data source. The DataSourceBinder can also
    ''' be used to populate an object with values from a data source.
    ''' </summary>
    Public Class DataSourceBinder

#Region " Constructor: "
        '*********************************************************************
        '   Constructor:

        ''' <summary>
        ''' Initializes a new instance of this class.
        ''' </summary>
        Public Sub New()

            MyBase.New()

        End Sub


#End Region     'Constructor:

#Region " Destructor: "
        '*********************************************************************
        '   Destructor:

        Protected Overrides Sub Finalize()

            MyBase.Finalize()

        End Sub

#End Region     'Destructor:

#Region " Public Methods: "
        '*********************************************************************
        '   Public Methods:

        '********************
        ' GetValues:
#Region " GetValues Overloads: "

        ''' <summary>
        ''' Returns a DataValuesDictionary instance containing the field and
        ''' property values for each member defined in the provided
        ''' MemberBindingCollection.
        ''' </summary>
        ''' <param name="obj">The object containing the member values.</param>
        ''' <param name="Memberbindings">MemberBindingCollection object,</param>
        ''' <returns>A DataValuesDictionary populated with values from the
        ''' provided object.</returns>
        Public Function GetValues(ByVal obj As Object, ByVal Memberbindings As MemberBindingCollection) As DataValuesDictionary

            If obj Is Nothing Then Throw New ArgumentNullException("obj")
            If Memberbindings Is Nothing Then Throw New ArgumentNullException("obj")

            Dim oRetVals As New DataValuesDictionary()
            Dim oBinding As MemberBinding
            For Each oBinding In Memberbindings
                oRetVals.Add(oBinding.FieldName, oBinding.GetValue(obj))
            Next

            Return oRetVals


        End Function


        ''' <summary>
        ''' Returns a DataValuesDictionary instance containing the field and
        ''' property values for each member decorated with a DataFieldAttribure.
        ''' </summary>
        ''' <param name="InstanceObject">The object containing the DataField
        ''' attributed fields and properties.</param>
        ''' <returns>A DataValuesDictionary populated with values from the
        ''' provided object.</returns>
        Public Function GetValues(ByVal InstanceObject As Object) As DataValuesDictionary

            If InstanceObject Is Nothing Then Throw New ArgumentNullException("InstanceObject")

            'Create MemberBindins from the DataField attributes.
            Dim oBindings As MemberBindingCollection _
            = DataFieldAttribute.GetMemberBindingsForType(InstanceObject.GetType)

            'Use the bindings to get the values.
            Return Me.GetValues(InstanceObject, oBindings)


        End Function

#End Region 'GetValues Overloads:


        '********************
        ' GetValuesIntoDataRow:
#Region " GetValuesIntoDataRow Overloads: "

        ''' <summary>
        ''' Inserts values in a DataValuesDictionary into a DataRow.
        ''' </summary>
        ''' <param name="Values">The DataValuesDictionary that will provide the source values.</param>
        ''' <param name="Row">The DataRow that will receive the values.</param>
        Public Sub GetValuesIntoDataRow(ByVal Values As DataValuesDictionary, _
                                        ByVal Row As DataRow)

            'Validate the parameters.
            If Values Is Nothing Then Throw New ArgumentNullException("Values")
            If Row Is Nothing Then Throw New ArgumentNullException("Row")

            Dim oCols As DataColumnCollection = Row.Table.Columns
            Dim sFieldName As String
            Dim oValueEntry As DictionaryEntry
            For Each oValueEntry In Values

                'If the current field name is found in the datarow then
                'set the field value with the value of the current field.
                sFieldName = DirectCast(oValueEntry.Key, String)
                If oCols.Contains(sFieldName) _
                AndAlso oCols(sFieldName).ReadOnly = False Then
                    Row(sFieldName) = oValueEntry.Value
                End If

            Next

        End Sub


        ''' <summary>
        ''' Inserts the values of an object into the a DataRow by
        ''' using a MemberBindingCollection to map the object
        ''' values to row fields.
        ''' </summary>
        ''' <param name="obj">The object that will provide the source values.</param>
        ''' <param name="MemberBindings">A MemberBindingCollection that will be used
        ''' to map object members to DataRow fields.</param>
        ''' <param name="Row">The DataRow that will receive the values.</param>
        Public Sub GetValuesIntoDataRow(ByVal obj As Object, _
                                        ByVal MemberBindings As MemberBindingCollection, _
                                        ByVal Row As DataRow)

            'Validate the parameters.
            If obj Is Nothing Then Throw New ArgumentNullException("obj")
            If MemberBindings Is Nothing Then Throw New ArgumentNullException("MemberBindings")

            'Collect the values into a DataValuesDictionary.
            Dim oValues As DataValuesDictionary _
            = Me.GetValues(obj, MemberBindings)

            'Fill the DataRow with the values from the DataValuesDictionary.
            Me.GetValuesIntoDataRow(oValues, Row)

        End Sub


        ''' <summary>
        ''' Inserts the values of an object into the a DataRow by
        ''' using the DataFieldAttribute decorated members of the object.
        ''' </summary>
        ''' <param name="InstanceObject">The object containing the DataField
        ''' attributed fields and properties.</param>
        ''' <param name="Row">The DataRow that will receive the values.</param>
        Public Sub GetValuesIntoDataRow(ByVal InstanceObject As Object, _
                                        ByVal Row As DataRow)

            'Validate the parameters.
            If InstanceObject Is Nothing Then Throw New ArgumentNullException("InstanceObject")
            'Collect the values into a DataValuesDictionary.
            Dim oValues As DataValuesDictionary _
            = Me.GetValues(InstanceObject)


            'Fill the DataRow with the values from the DataValuesDictionary.
            Me.GetValuesIntoDataRow(oValues, Row)

        End Sub

#End Region 'GetValuesIntoDataRow Overloads:


        '********************
        ' GetValuesIntoParameterCollection:
#Region " GetValuesIntoParameterCollection Overloads: "

        ''' <summary>
        ''' Transfers The values from a DataValuesDictionary instance into the
        ''' provided IDataParameterCollection.
        ''' </summary>
        ''' <param name="Values">A DataValuesDictionary instance.</param>
        ''' <param name="Parameters">The IDataParameterCollection that
        ''' will receive the values.</param>
        ''' <param name="ParamPrefix">The prefix text that preceeds the parameter names.
        ''' The default value is "@".</param>
        ''' <param name="IdentityKeyField">Optional. If the IdentityKeyField
        ''' is provided then it should be set to the Field name in the dictionary that
        ''' contains the Identity key value for the data source. </param>
        ''' <param name="IdentityParameterName">Optional. The name of the
        ''' IDbDataParameter that is the identity key parameter. The default value is "@IdentityKey".</param>
        ''' <remarks>
        ''' This method assumes the parameter names match the field names found in the the DataValuesDictionary. A parameter name can contain a leading "@" symbol. This symbol is ignored when comparing parameter names to field names.
        ''' <para>
        ''' You can optionally define a field as an Identity key field for the datasource. This is done by providing the name of a DataValuesDictionary field that that contains the identity data to the IdentityKeyField parameter and providing the name of the IDbDataParameter that is the identity key in the Parameters collection to the IdentityParameterName parameter.
        ''' </para>
        ''' <para>If a dictionary member does not have a corresponding parameter with a matching name then that member is ignored.
        ''' </para>
        ''' </remarks> 
        Public Sub GetValuesIntoParameterCollection(ByVal Values As DataValuesDictionary, _
                                                    ByVal Parameters As IDataParameterCollection, _
                                                    Optional ByVal ParamPrefix As String = Nothing, _
                                                    Optional ByVal IdentityKeyField As String = Nothing, _
                                                    Optional ByVal IdentityParameterName As String = Nothing)

            'Validate the parameters.
            If Values Is Nothing Then Throw New ArgumentNullException("Values")
            If Parameters Is Nothing Then Throw New ArgumentNullException("Parameters")
            If IdentityKeyField Is Nothing Then
                IdentityKeyField = String.Empty
            Else
                IdentityKeyField = IdentityKeyField.Trim
            End If
            If ParamPrefix Is Nothing Then ParamPrefix = "@"
            If IdentityParameterName Is Nothing Then IdentityParameterName = "@IdentityKey"

            Dim oParameter As IDbDataParameter
            Dim sParamName As String
            Dim oValue As Object

            'Iterate through all the parameters in the passed collection.
            For Each oParameter In Parameters

                oValue = Nothing
                sParamName = oParameter.ParameterName

                'Attempt to get the matching field value for the current parameter.
                'If the parameter name starts with ParamPrefix...
                If sParamName.StartsWith(ParamPrefix) Then
                    'Atempt to find the field value of the parameter name without
                    'the leading ParamPrefix.
                    oValue = Values(sParamName.Substring(ParamPrefix.Length))

                End If

                'If the field was not found (or the parameter does not start with ParamPrefix)
                'then use the full parameter name to search for the value.
                If oValue Is Nothing Then oValue = Values(sParamName)

                'If the value is not nothing then set the IDbDataParameter value to 
                'to the member value.
                If Not oValue Is Nothing Then oParameter.Value = oValue

            Next

            'If an identity key field was defined then attampt to populate the 
            'identity parameter with the value of the identity field.
            If IdentityKeyField.Length <> 0 Then
                oValue = Values(IdentityKeyField)
                oParameter = DirectCast(Parameters(IdentityParameterName), IDbDataParameter)
                If (Not oValue Is Nothing) _
                AndAlso (Not oParameter Is Nothing) Then
                    oParameter.Value = oValue
                End If
            End If

        End Sub


        ''' <summary>
        ''' Transfers The values from an object into the provided
        ''' IDataParameterCollection.
        ''' </summary>
        ''' <param name="obj">The object that contains the values.</param>
        ''' <param name="MemberBindings">A MemberBindingCollection that maps the objects member values
        ''' with parameter names.</param>
        ''' <param name="Parameters">The IDataParameterCollection that
        ''' will receive the values.</param>
        ''' <param name="ParamPrefix">The prefix text that preceeds the parameter names.
        ''' The default value is "@".</param>
        ''' <param name="IdentityKeyField">Optional. If the IdentityKeyField
        ''' is provided then it should be set to the Field name in the dictionary that
        ''' contains the Identity key value for the data source. </param>
        ''' <param name="IdentityParameterName">Optional. The name of the
        ''' IDbDataParameter that is the identity key parameter. The default value is "@IdentityKey".</param>
        Public Sub GetValuesIntoParameterCollection(ByVal obj As Object, _
                                                    ByVal MemberBindings As MemberBindingCollection, _
                                                    ByVal Parameters As IDataParameterCollection, _
                                                    Optional ByVal ParamPrefix As String = Nothing, _
                                                    Optional ByVal IdentityKeyField As String = Nothing, _
                                                    Optional ByVal IdentityParameterName As String = Nothing)

            'Validate the parameters.
            If obj Is Nothing Then Throw New ArgumentNullException("obj")
            If MemberBindings Is Nothing Then Throw New ArgumentNullException("MemberBindings")

            'Load the member values into a DataValuesDictionary.
            Dim oValues As DataValuesDictionary _
            = Me.GetValues(obj, MemberBindings)

            'Load the values into the parameters collection.
            GetValuesIntoParameterCollection(oValues, Parameters, ParamPrefix, IdentityKeyField, IdentityParameterName)

        End Sub


        ''' <summary>
        ''' Transfers the DataField attributed values of the provided object
        ''' into the provided IDataParameterCollection.
        ''' </summary>
        ''' <param name="InstanceObject">The object containing fields and properties
        ''' decorated with the DataFieldAttribute.</param>
        ''' <param name="Parameters">The IDataParameterCollection instance that
        ''' will receive the values.</param>
        ''' <param name="ParamPrefix">The prefix text that preceeds the parameter names.
        ''' The default value is "@".</param>
        ''' <param name="IdentityParameterName">Optional. The name of the
        ''' IDbDataParameter that is the identity key parameter. The default value is "@IdentityKey".</param>
        Public Sub GetValuesIntoParameterCollection(ByVal InstanceObject As Object, _
                                                    ByVal Parameters As IDataParameterCollection, _
                                                    Optional ByVal ParamPrefix As String = Nothing, _
                                                    Optional ByVal IdentityParameterName As String = Nothing)

            If InstanceObject Is Nothing Then Throw New ArgumentNullException("InstanceObject")
            If Parameters Is Nothing Then Throw New ArgumentNullException("Parameters")

            'Get the name of the Identity field so it can be tested.
            Dim sIdentityField As String = Me.GetIdentityFieldName(InstanceObject.GetType)

            'Get the DataField decorated members into a DataValuesDictionary.
            Dim oValues As DataValuesDictionary = GetValues(InstanceObject)

            'Load the values into the parameters collection.
            GetValuesIntoParameterCollection(oValues, Parameters, ParamPrefix, sIdentityField, IdentityParameterName)


        End Sub

#End Region 'GetValuesIntoParameterCollection Overloads:


        '********************
        ' GetIdentityFieldName:
        ''' <summary>
        ''' Returns the name of the Identity field defined in the provided type.
        ''' </summary>
        ''' <param name="Type">A Type object decorated with an IdentityFieldAttribute.</param>
        ''' <returns>The name of the Identity field or null (Nothing) if there is no IdentityFieldAttribute.</returns>
        Public Function GetIdentityFieldName(ByVal [Type] As Type) As String

            Dim oIFAtt As IdentityFieldAttribute
            Dim sIdentityFieldName As String

            'Get the name of the Identity field so it can be tested.
            oIFAtt = DirectCast(Attribute.GetCustomAttribute([Type], GetType(IdentityFieldAttribute), True), IdentityFieldAttribute)
            If Not oIFAtt Is Nothing Then
                sIdentityFieldName = oIFAtt.IdentityField
            End If

            Return sIdentityFieldName

        End Function


        '********************
        ' GetIdentityFieldValue:
        ''' <summary>
        ''' Returns The Value of the member whose DataField attribute
        ''' FieldName property matches the DataTable attribute IdentityField
        ''' property.
        ''' </summary>
        ''' <param name="InstanceObject">The object containing the DataField
        ''' attributed fields and properties.</param>
        ''' <returns></returns>
        Public Function GetIdentityFieldValue(ByVal InstanceObject As Object) As Object

            Dim sIdentityFieldName As String
            Dim oIDValue As Object

            'Get the DataTable attribute for this type.
            Dim oIDFieldAtt As IdentityFieldAttribute _
            = Me.GetIdentityFieldAttribute(InstanceObject.GetType)


            'Extract the Identity field name from the DataTable attribute.
            sIdentityFieldName = FixDBName(oIDFieldAtt.IdentityField)


            'Iterate through each member field until the Identity value is found.
            Dim oMemberValues As DataValuesDictionary = Me.GetValues(InstanceObject)
            Dim oValueEntry As DictionaryEntry
            Dim sFieldName As String
            For Each oValueEntry In oMemberValues

                'Check if the current field name matches the ID field name.
                sFieldName = DirectCast(oValueEntry.Key, String)
                If FixDBName(sFieldName) = sIdentityFieldName Then
                    'If so, get the value and exit the loop.
                    oIDValue = oMemberValues(sFieldName)
                    Exit For
                End If
            Next

            If oIDValue Is Nothing Then
                'Throw exception if no IdentityKey member is defined.
                Throw New Exception("no members with the matching identity key name could be found.")
            End If

            Return oIDValue

        End Function


        '********************
        ' SetValues Overloads:
#Region " SetValues Overloads:"

        ''' <summary>
        ''' Sets the values for the provided object.
        ''' </summary>
        ''' <param name="obj">An object that will receive the values</param>
        ''' <param name="MemberBindings">A MemberBindingCollection that maps
        ''' the values in the DataValuesDictionary to members of the object.</param>
        ''' <param name="Values">DataValuesDictionary that contains the values.</param>
        ''' <param name="IgnoreWhenNotSet"></param>
        Public Sub SetValues(ByVal obj As Object, _
                             ByVal MemberBindings As MemberBindingCollection, _
                             ByVal Values As DataValuesDictionary, _
                             Optional ByVal IgnoreWhenNotSet As Boolean = False)

            'Validate the parameters.
            If obj Is Nothing Then Throw New ArgumentNullException("obj")
            If MemberBindings Is Nothing Then Throw New ArgumentNullException("MemberBindings")
            If Values Is Nothing Then Throw New ArgumentNullException("Values")


            Dim oMemberBinding As MemberBinding
            'Get the DataField decorated members into a hash table
            'and iterate through them.
            For Each oMemberBinding In MemberBindings

                'Catch exceptions so they can be wrapped into 
                'something more descriptive.
                Try


                    'Pull the value for this field from the DataValuesDictionary.
                    If Values.ContainsField(oMemberBinding.FieldName) Then
                        oMemberBinding.SetValue(obj, Values(oMemberBinding.FieldName))

                    ElseIf IgnoreWhenNotSet = False Then
                        'If no value for this member was found in the dictionary
                        'then set the member's value to null.
                        oMemberBinding.SetValue(obj, Nothing)

                    End If



                Catch x As Exception
                    Throw New ApplicationException("Error while setting value for """ & oMemberBinding.FieldName & """: " & x.Message, x)

                End Try

            Next


        End Sub

        ''' <summary>
        ''' Sets the values for the provided object.
        ''' </summary>
        ''' <param name="InstanceObject">
        ''' The DataField attributed object that
        ''' will receive the values.
        ''' </param>
        ''' <param name="Values">
        ''' An DataValuesDictionary that contains the values
        ''' that will be inserted into the object.
        ''' </param>
        ''' <param name="IgnoreWhenNotSet">
        ''' When set to False, The object member
        ''' value is set to null(Nothing) If a field for the member can not be
        ''' found in the provided DataValuesDictionary. When True The member
        ''' value will not be changed.
        ''' The default value for this property is False.
        ''' </param>
        Public Sub SetValues(ByVal InstanceObject As Object, _
                            ByVal Values As DataValuesDictionary, _
                            Optional ByVal IgnoreWhenNotSet As Boolean = False)

            'Load a MemberBindingCollection from the object.
            Dim oMemberBindings As MemberBindingCollection _
            = DataFieldAttribute.GetMemberBindingsForType(InstanceObject.GetType)

            'Populate the object with values.
            Call Me.SetValues(InstanceObject, oMemberBindings, Values, IgnoreWhenNotSet)

        End Sub


        ''' <summary>
        ''' Sets the values for the provided object.
        ''' </summary>
        ''' <param name="obj"> The  object that will receive the values.</param>
        ''' <param name="MemberBindings">A MemberBindingCollection that maps
        ''' the values in the DataRow to members of the object.</param>
        ''' <param name="Values">
        ''' An dataRow that contains the values
        ''' that will be inserted into the object.
        ''' </param>
        ''' <param name="IgnoreWhenNotSet">
        ''' When set to False, The object member
        ''' value is set to null(Nothing) If a field for the member can not be
        ''' found in the provided DataValuesDictionary. When True The member
        ''' value will not be changed.
        ''' The default value for this property is False.
        ''' </param>
        Public Sub SetValues(ByVal obj As Object, _
                             ByVal MemberBindings As MemberBindingCollection, _
                             ByVal Values As DataRow, _
                             Optional ByVal IgnoreWhenNotSet As Boolean = False)

            If Values Is Nothing Then Throw New ArgumentNullException("Values")

            Dim oCol As DataColumn
            Dim oValues As New DataValuesDictionary()


            'Load the datarow values into an DataValuesDictionary, 
            For Each oCol In Values.Table.Columns
                oValues(oCol.ColumnName) = Values(oCol)
            Next

            'Use the DataValuesDictionary to set the object member values.
            Call SetValues(obj, MemberBindings, oValues, IgnoreWhenNotSet)

        End Sub


        ''' <summary>
        ''' Sets the values for the provided object.
        ''' </summary>
        ''' <param name="InstanceObject">
        ''' The DataField attributed object that
        ''' will receive the values.
        ''' </param>
        ''' <param name="Values">
        ''' An dataRow that contains the values
        ''' that will be inserted into the object.
        ''' </param>
        ''' <param name="IgnoreWhenNotSet">
        ''' When set to False, The object member
        ''' value is set to null(Nothing) If a field for the member can not be
        ''' found in the provided DataValuesDictionary. When True The member
        ''' value will not be changed.
        ''' The default value for this property is False.
        ''' </param>
        Public Sub SetValues(ByVal InstanceObject As Object, _
                            ByVal Values As DataRow, _
                            Optional ByVal IgnoreWhenNotSet As Boolean = False)

            If Values Is Nothing Then Throw New ArgumentNullException("Values")

            Dim oCol As DataColumn
            Dim oValues As New DataValuesDictionary()

            'Load the datarow values into an DataValuesDictionary, 
            For Each oCol In Values.Table.Columns
                oValues(oCol.ColumnName) = Values(oCol)
            Next

            'Use the DataValuesDictionary to set the object member values.
            Call SetValues(InstanceObject, oValues, IgnoreWhenNotSet)

        End Sub


#End Region     ' SetValues Overloads:


        '********************
        ' FixDBName:
        ''' <summary>
        ''' Prepares the passed name to be used as a valid Sql name.
        ''' </summary>
        ''' <param name="Name">The name to be prepared</param>
        ''' <param name="NoBraces">Then set to True, the returned value
        ''' will not be sourrounded with braces([]). Braces will be added
        ''' when False. The default value for this property is False.</param>
        ''' <returns></returns>
        Public Function FixDBName(ByVal Name As String, Optional ByVal NoBraces As Boolean = False) As String

            Dim oSB As New System.Text.StringBuilder(Name.Trim)
            If oSB.Length = 0 Then Throw New ArgumentException("Name can not be an empty string.")

            If NoBraces = False Then

                'NoBraces = False. Insert the braces if they do not exist.
                If oSB.Chars(0) <> "[" Then
                    oSB.Insert(0, "[")
                End If

                If oSB.Chars(oSB.Length - 1) <> "]" Then
                    oSB.Append("]")
                End If


            Else

                'NoBraces = True. Remove the braces if they exist.
                oSB.Replace("[", String.Empty)
                oSB.Replace("]", String.Empty)

            End If

            Return oSB.ToString.Trim

        End Function

#End Region     'Public Methods:

#Region " Protected Methods: "
        '*********************************************************************
        '   Protected Methods:

        '********************
        ' GetDataboundMembers:
        ''' <summary>
        ''' Get all the object members decorated with the DataFieldAttribute.
        ''' </summary>
        ''' <param name="InstanceObjectType"></param>
        ''' <returns></returns>
        Protected Function GetDataboundMembers(ByVal InstanceObjectType As Type) As Hashtable

            Dim oMember As MemberInfo
            Dim oDFAtt As DataFieldAttribute
            Dim oMembers As New Hashtable()

            'Iterate through all public and private instance members.
            For Each oMember In InstanceObjectType.GetMembers(BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance)

                'Attempt to get a DataField attribute from the member.
                'If an attribute is retreived then add the member to the hash table,
                'using the attribute as the key.
                oDFAtt = DirectCast(Attribute.GetCustomAttribute(oMember, GetType(DataFieldAttribute)), DataFieldAttribute)
                If Not oDFAtt Is Nothing Then
                    oMembers(oDFAtt) = oMember
                End If

            Next

            Return oMembers

        End Function


        '********************
        ' IdentityFieldAttribute:
        ' Get the IdentityFieldAttribute from the provided type.
        ' Throw an exception if noe is defined.
        ''' <summary>
        ''' Get the IdentityFieldAttribute from the provided type.
        ''' Throw an exception if noe is defined.
        ''' </summary>
        ''' <param name="InstanceObjectType"></param>
        ''' <returns></returns>
        Protected Function GetIdentityFieldAttribute(ByVal InstanceObjectType As Type) As IdentityFieldAttribute

            Dim oIDFieldAtt As IdentityFieldAttribute _
            = IdentityFieldAttribute.GetIdentityFieldAttributeFromType(InstanceObjectType)

            If oIDFieldAtt Is Nothing Then _
                Throw New ArgumentException("The provided type does not have a IdentityFieldAttribute defined.")

            Return oIDFieldAtt

        End Function

#End Region     'Protected Methods:



    End Class

#End Region     'DataSourceBinder Class:

End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I was born in Colorado but have lived most of my life in Southern California. I live a largely ordinary life with occasional extraordinary intervening events.

I am an independent contractor who is blessed to have the opportunity to do work that I love and still earn enough money to pay the bills.

Comments and Discussions