Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# discussion: Redundant class names?
Message
De
29/07/2008 15:26:13
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
29/07/2008 15:14:40
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01334856
Message ID:
01335055
Vues:
13
>Read the book C# in Depth for a clear description of delegates.
>
>>I would second that and while you are at it, naming of delegates, handlers, events as there is so much confusion amongst writers that it was the hardest part for me in learning this topic. Some called the delegates ConnectionStateChangedDelegate and others called it ConnectionStateChangedHandler and others OnConnectionStateChanged. I have decided what is right for me.
>>
>>Tim

Hi Craig,

I have a clear description of delegates now and use them extensively. I just had a hard time becuase everything I read used different naming for the different pieces which made it really hard to follow and figure out.
This is my naming: This makes it clear for me although not consistent with everyone else.
public delegate void ConnectionStateChangedDelegate(Object sender, ConnectionStateChangedEventArgs e);

public class ConnectionStateChangedEventArgs : EventArgs
{
     public readonly bool IsConnected;
     public readonly string Message;

     public ConnectionStateChangedEventArgs(bool isConnected, string message)
     {
          this.IsConnected = isConnected;
          this.Message = message;
     }
}

/// <summary>
/// Connection State Changed Event
/// </summary>
public event ConnectionStateChangedDelegate ConnectionStateChanged;

/// <summary>
/// Raises the Connection State Changed Event
/// </summary>
private void OnConnectionStateChanged(bool connectState)
{
     this._connected = connectState;
     string message = "Disconnected!";

     ConnectionStateChangedDelegate csc = this.ConnectionStateChanged;
     if (csc != null)
     {
          if (this._connected)
          message = "Connected on " + gps.PortName;

          // Raise the event
          this.ConnectionStateChanged(this, new ConnectionStateChangedEventArgs(this._connected, message));
     }
}
Tim
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform