There are many constructors for this class. I am not sure which one gets called when the type T is String.
--------------------------------------------------------------------------------------------------------------------------------
Public Class PropertyInfo(Of T)
Public
Sub New(ByVal name As String, ByVal friendlyName As String)Public
Sub New(ByVal name As String, ByVal defaultValue As T)End
Class--------------------------------------------------------------------------------------------------------------------------------
In the code below, I am trying to set the Friendly name as the 2nd parameter. But how do I know it is not really setting the defaultValue which is also the 2nd parameter of a different constructor? Which constructor is really getting called in this case?
e.g. Dim x As PropertyInfo(Of String) = New PropertyInfo(Of String)("Data", "Object data")
Joe
Rocky,
I agree that removing it is a good idea.
While trying to create a subclass for PropertyInfo(Of T) I am having some trouble with the defaultValue. You made the Property Overridable but did not give us access to the Private variable _defaultValue. This caused me to have to create my own variable in my subclass and then use it inside the overridden Property. Can you do one of these 2 suggestions:
1. Make _defaultValue Protected instead of Private.
2. Create a Protected Overridable function named GetDefaultValue As T.
Then call that function inside the constructor with 2 parameters:
Public Sub New(ByVal name As String, ByVal friendlyName As String)
Protected Overridable
Function GetDefaultValue() As TBy doing this I can override the function and add defaults for numeric values too.
e.g.
Protected Overrides Function GetDefaultValue() As T
...
ElseIf GetType(T).Equals(GetType(Integer)) OrElse GetType(T).Equals(GetType(Long)) OrElse GetType(T).Equals(GetType(Decimal)) OrElse GetType(T).Equals(GetType(Short)) OrElse GetType(T).Equals(GetType(Byte)) Then
result = DirectCast(DirectCast(0, Object), T)
...
End Function
Joe
Copyright (c) Marimer LLC