Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Event Conversion vb.net to c#
    primarykey
    data
    text
    <p>I'm having some issues with converting a custom event from vb.net to c#, I have no experience of vb.net really, and i have even less experience with these custom events, the rest of the application was converted without much issue, however this one has me stuck. The converters that i have used (both paid and free) have all failed to produce usable code. </p> <p>VB.net code:</p> <pre class="lang-vb prettyprint-override"><code>&lt;NonSerialized()&gt; Private _objNonSerializablePropertyChangedHandlers As New System.ComponentModel.EventHandlerList '''' &lt;summary&gt; '''' Raised when a public property of this object is set. '''' &lt;/summary&gt; Public Custom Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged AddHandler(ByVal value As PropertyChangedEventHandler) Me.NonSerializablePropertyChangedHandlers.AddHandler(STR_PROPERTYCHANGEDEVENT, value) End AddHandler RemoveHandler(ByVal value As PropertyChangedEventHandler) Me.NonSerializablePropertyChangedHandlers.RemoveHandler(STR_PROPERTYCHANGEDEVENT, value) End RemoveHandler RaiseEvent(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Dim obj As PropertyChangedEventHandler = TryCast(Me.NonSerializablePropertyChangedHandlers(STR_PROPERTYCHANGEDEVENT), PropertyChangedEventHandler) If obj IsNot Nothing Then obj.Invoke(sender, e) End If End RaiseEvent </code></pre> <p>the best i have managed to produce in c# is the following:</p> <p>C#</p> <pre class="lang-cs prettyprint-override"><code>[NonSerialized()] private System.ComponentModel.EventHandlerList _objNonSerializablePropertyChangedHandlers = new System.ComponentModel.EventHandlerList(); public event PropertyChangedEventHandler PropertyChanged { add { this.NonSerializablePropertyChangedHandlers.AddHandler(STR_PROPERTYCHANGEDEVENT, value); } remove { this.NonSerializablePropertyChangedHandlers.RemoveHandler(STR_PROPERTYCHANGEDEVENT, value); } } protected void OnPropertyChanged(string strPropertyName) { EventHandler handler = this.PropertyChanged; if (handler != null) { handler.Invoke(this, new PropertyChangedEventArgs(strPropertyName)); //PropertyChanged(this, new PropertyChangedEventArgs(strPropertyName)); } } </code></pre> <p>However this throws an error "The event 'CardBase.PropertyChanged' can only appear on the left hand side of += or -="</p> <p>on the line : EventHandler handler = this.PropertyChanged;</p> <p>As i'm not 100% on what the above code is doing, im struggling to fix this myself, I would be very grateful is someone could assist on this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload