Listing 3: Updated myPointType
Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports System.Data.SqlServer
<Serializable()> _
<SqlUserDefinedType(Format.Native)> _
Public Structure myPointType
Implements INullable
#Region "Private Values"
' This is a place-holder field member
Private m_xAxis As Integer
Private m_yAxis As Integer
' Private member
Private m_Null As Boolean
#End Region
#Region "Constructors"
Public Sub New(ByVal xAxis As Integer, ByVal yAxis As Integer)
m_xAxis = xAxis
m_yAxis = yAxis
m_Null = False
End Sub
Private Sub New(ByVal isnull As Boolean)
m_Null = isnull
m_xAxis = 0
m_yAxis = 0
End Sub
#End Region
#Region "Public Properties"
''' <summary>
''' Provide access to the x axis for thepoint
''' </summary>
''' <value></value>
''' <remarks></remarks>
Public Property xAxis() As Integer
Get
Return m_xAxis
End Get
Set(ByVal value As Integer)
m_xAxis = value
End Set
End Property
''' <summary>
''' Provide access to the y axis for the point
''' </summary>
''' <value></value>
''' <remarks></remarks>
Public Property yAxis() As Integer
Get
Return m_yAxis
End Get
Set(ByVal value As Integer)
m_yAxis = value
End Set
End Property
''' <summary>
''' Indicates if the current value is null.
''' </summary>
''' <value></value>
''' <remarks></remarks>
Public ReadOnly Property IsNull() As Boolean Implements INullable.IsNull
Get
' Put your code here
Return m_Null
End Get
End Property
''' <summary>
''' This method returns an instance of the UDT that is null.
''' </summary>
''' <value></value>
''' <remarks></remarks>
Public Shared ReadOnly Property Null() As myPointType
Get
Dim h As myPointType = New myPointType
h.m_Null = True
Return h
End Get
End Property
#End Region
#Region "Public Shared Functions"
''' <summary>
''' This method attempts to convert a value into a new point, returning a valid instance.
''' This method could be overloaded to support multiple conversions. For now I'll just
''' provide an implementation that accepts the 'ToSTring()' format above.
''' </summary>
''' <param name="s"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function Parse(ByVal s As SqlString) As myPointType
If s.IsNull Then
Return Null
End If
Dim str As String = s.ToString()
'In theory there should be a great deal more error handling here to ensure that the string is
' formated "(#,#)"
Dim intComma As Integer
intComma = str.IndexOf(",")
Dim u As myPointType = New myPointType
' Put your code here
Return u
End Function
#End Region
#Region "Public Instance Methods"
''' <summary>
''' Override the default ToString implementation to return
''' a string representation of this point value.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Overrides Function ToString() As String
If m_Null Then
Return ""
End If
Return "(" + m_xAxis.ToString() + "," + m_yAxis.ToString() + ")"
End Function
'This region could also contain public methods to return a .NET point value from this database
' version of a custom Point UDT.
' This is a place-holder method
'Public Function Method1() As String
' ' Put your code here
' Return "Hello"
'End Function
'' This is a place-holder static method
'Public Shared Function Method2() As SqlString
' ' Put your code here
' Return New SqlString("Hello")
'End Function
#End Region
End Structure