|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GetType of custom Property set to nothingnothing Also I thought about creating a function so I don't have to put so many if statement for each property for each classes etc. However if I call ReturnValue(myClass.CompanyName) and CompanyName is Nothing then it crash where it shoud return SqlTypes.SqlString.Null Private _CompanyName As String <ComponentModel.Browsable(True), ComponentModel.Description("CompanyName"), ComponentModel.ReadOnly(False)> _ Public Property CompanyName() As String Implements iCompany.CompanyName Get Return _CompanyName End Get Set(ByVal Value As String) Me._CompanyName = Value End Set End Property Function ReturnValue(ByVal thisObject As Object) As Object Try If IsNothing(thisObject) Then """"" CRASH HERE """ Because thisObject is nothing so I cannot get the type Select Case thisObject.GetType.ToString Case GetType(System.String).ToString Return SqlTypes.SqlString.Null Case GetType(System.Boolean).ToString Return SqlTypes.SqlBoolean.Null Case Else Return SqlTypes.SqlString.Null End Select Else Return thisObject End If Catch ex As Exception Return SqlTypes.SqlString.Null End Try End Function Thanks for the help Nicolas
Show quote
Hide quote
> Function ReturnValue(ByVal thisObject As Object) As Object If you want to return null if the object is nothing, try:> Try > If IsNothing(thisObject) Then > > """"" CRASH HERE """ Because thisObject is nothing so I cannot get the > type > Select Case thisObject.GetType.ToString > Case GetType(System.String).ToString > Return SqlTypes.SqlString.Null > Case GetType(System.Boolean).ToString > Return SqlTypes.SqlBoolean.Null > Case Else > Return SqlTypes.SqlString.Null > End Select > Else > Return thisObject > End If > > Catch ex As Exception > Return SqlTypes.SqlString.Null > End Try > End Function > > Nick, Function ReturnValue(ByVal Value As Object) As Object If Value Is Nothing Return DBNull.Value Else Return Value End If End Function HTH, Mythran |
|||||||||||||||||||||||