Steps to reproduce:
- Naming convention for parameters is _PascalCase
- Start with the code:
Visual BasicImports System.ComponentModel
Public Class Class3
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Sub NotifyPropertyChanged(_PropertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(_PropertyName))
End Sub
Private m_Prop1 As String
Private m_Prop2 As GenericEventArgs(Of GenericResultFlags)
Public Property Prop1 As String
Get
Return m_Prop1
End Get
Set(_Value As String)
If m_Prop1 Is _Value Then
Return
End If
m_Prop1 = _Value
NotifyPropertyChanged(NameOf(Prop1))
End Set
End Property
Public Property Prop2 As GenericEventArgs
Get
Return m_Prop2
End Get
Set(_Value As GenericEventArgs)
If m_Prop2 = _Value Then
Return
End If
m_Prop2 = _Value
NotifyPropertyChanged(NameOf(Prop2))
End Set
End Property
Public Sub New(ByVal _Prop1 As String, ByVal _Prop2 As GenericEventArgs)
m_Prop1 = _Prop1
m_Prop2 = _Prop2
End Sub
End Class
- Execute the Implement ISerializable code provider
Expected results:
Visual BasicProtected Sub New(_Info As SerializationInfo, _Context As StreamingContext)
If _Info Is Nothing Then
Throw New ArgumentNullException(NameOf(_Info), $"{NameOf(_Info)} is null.")
End If
m_Prop1 = _Info.GetString(NameOf(m_Prop1))
m_Prop2 = CType(_Info.GetValue(NameOf(m_Prop2), GetType(GenericEventArgs)), GenericEventArgs)
End Sub
Protected Overridable Sub GetObjectData(_Info As SerializationInfo, _Context As StreamingContext) Implements ISerializable.GetObjectData
If _Info Is Nothing Then
Throw New ArgumentNullException(NameOf(_Info), $"{NameOf(_Info)} is null.")
End If
_Info.AddValue(NameOf(m_Prop1), m_Prop1)
_Info.AddValue(NameOf(m_Prop2), m_Prop2)
End Sub
Current results:
Visual BasicProtected Sub New(info As SerializationInfo, context As StreamingContext)
If info Is Nothing Then
Throw New ArgumentNullException(NameOf(info), $"{NameOf(info)} is null.")
End If
m_Prop1 = info.GetString(NameOf(m_Prop1))
m_Prop2 = CType(info.GetValue(NameOf(m_Prop2), GetType(GenericEventArgs)), GenericEventArgs)
End Sub
Protected Overridable Sub GetObjectData(info As SerializationInfo, context As StreamingContext) Implements ISerializable.GetObjectData
If info Is Nothing Then
Throw New ArgumentNullException(NameOf(info), $"{NameOf(info)} is null.")
End If
info.AddValue(NameOf(m_Prop1), m_Prop1)
info.AddValue(NameOf(m_Prop2), m_Prop2)
End Sub
I dont know if this helps but I just noticed something. I am the middle of making a custom exception. To Repro, make a new class that inherits from Exception and has 4 private members. haha. I chose Generate All (constructors) from the action context menu , the resulting constructors dont respect my rules. I delete the serialization constructor and then I chose Generate Constructor from the action context menu and i pick my 4 members. haha. When I do this, my rules are respected. I dont know if one is VS and the other CR or what. Below is the resulting code:
Public Class ConversionException Inherits Exception Private m_ExpectedType As Type Private m_InitialType As Type Private m_Message As String Private m_Value As Object Public Sub New() End Sub Public Sub New(message As String) MyBase.New(message) End Sub Public Sub New(message As String, innerException As Exception) MyBase.New(message, innerException) End Sub Public Sub New(_ExpectedType As Type, _InitialType As Type, _Message As String, _Value As Object) ExpectedType = _ExpectedType InitialType = _InitialType Message1 = _Message Value = _Value End Sub End Class
This is what I expected to get
Public Class ConversionException Inherits Exception Private m_ExpectedType As Type Private m_InitialType As Type Private m_Message As String Private m_Value As Object Public Sub New() End Sub Public Sub New(_Message As String) MyBase.New(_Message) End Sub Public Sub New(_Message As String, _InnerException As Exception) MyBase.New(_Message, _InnerException) End Sub Public Sub New(_ExpectedType As Type, _InitialType As Type, _Message As String, _Value As Object) ExpectedType = _ExpectedType InitialType = _InitialType Message1 = _Message Value = _Value End Sub End Class
I hope it helps