Click here to Skip to main content
15,919,778 members
Home / Discussions / C#
   

C#

 
GeneralRe: Float divisoin Pin
Pete Bassett29-Oct-02 1:20
Pete Bassett29-Oct-02 1:20 
GeneralRe: Float divisoin Pin
Nick Parker29-Oct-02 1:21
protectorNick Parker29-Oct-02 1:21 
GeneralRe: Float divisoin Pin
Mazdak29-Oct-02 4:03
Mazdak29-Oct-02 4:03 
GeneralDrag and Drop Pin
Buddhi28-Oct-02 23:36
Buddhi28-Oct-02 23:36 
QuestionHow to count event subscriptions Pin
BigAndy28-Oct-02 23:11
BigAndy28-Oct-02 23:11 
AnswerRe: How to count event subscriptions Pin
Stephane Rodriguez.29-Oct-02 0:04
Stephane Rodriguez.29-Oct-02 0:04 
GeneralRe: How to count event subscriptions Pin
BigAndy29-Oct-02 1:28
BigAndy29-Oct-02 1:28 
GeneralRe: How to count event subscriptions Pin
Stephane Rodriguez.29-Oct-02 1:56
Stephane Rodriguez.29-Oct-02 1:56 
More info on delegate type is needed to provide full source code.

I guess this code will be helpful :
class App {

   // Definition of delegate that allows quering a component's status
   delegate String GetStatus();

   static void Main() {
      // Declare an empty delegate chain
      GetStatus getStatus = null;

      // Construct the 3 components and add their status methods 
      // to the delegate chain
      getStatus += new GetStatus(new Light().SwitchPosition);
      getStatus += new GetStatus(new Fan().Speed);
      getStatus += new GetStatus(new Speaker().Volume);

      // Show consolidated status report reflecting 
      // the condition of the 3 components
      Console.WriteLine(GetComponentStatusReport(getStatus));
   }

   // Method that queries several components and returns a status report
   static String GetComponentStatusReport(GetStatus status) {

      // If the chain is empty, there is nothing to do
      if (status == null) return null;

      // Use this to build the status report
      StringBuilder report = new StringBuilder();

      // Get an array where each element is a delegate from the chain
      Delegate[] arrayOfDelegates = status.GetInvocationList();

      // Iterate over each delegate in the array 
      foreach (GetStatus getStatus in arrayOfDelegates) {

         try {
            // Get a component's status string and append it to the report
            report.Append(getStatus() + "\r\n\r\n");
         }
         catch (Exception e) {
            // Generate an error entry in the report for this component
            Object component = getStatus.Target;
            report.Append("Failed to get status from " +
               ((component == null) ? "" : component.GetType() + ".") + 
               getStatus.Method.Name + 
               "\r\n   Error: " + e.Message + "\r\n\r\n");
         }
      }

      // Return the consolidated report to the caller
      return report.ToString();
   }
}




How low can you go ?
(MS rant)

GeneralC# .NET and Microsoft Excel Pin
mee28-Oct-02 16:22
mee28-Oct-02 16:22 
GeneralRe: C# .NET and Microsoft Excel Pin
Paul Riley29-Oct-02 0:08
Paul Riley29-Oct-02 0:08 
GeneralRe: C# .NET and Microsoft Excel Pin
mee29-Oct-02 16:07
mee29-Oct-02 16:07 
GeneralDebugging managed and unmanaged Pin
Anonymous28-Oct-02 6:57
Anonymous28-Oct-02 6:57 
GeneralRe: Debugging managed and unmanaged Pin
Stephane Rodriguez.28-Oct-02 7:29
Stephane Rodriguez.28-Oct-02 7:29 
GeneralRe: Debugging managed and unmanaged Pin
Anonymous28-Oct-02 8:08
Anonymous28-Oct-02 8:08 
GeneralRe: Debugging managed and unmanaged Pin
Paul Riley28-Oct-02 8:19
Paul Riley28-Oct-02 8:19 
GeneralRe: Debugging managed and unmanaged Pin
Stephane Rodriguez.28-Oct-02 8:21
Stephane Rodriguez.28-Oct-02 8:21 
GeneralRe: Debugging managed and unmanaged Pin
Gaul29-Oct-02 8:00
Gaul29-Oct-02 8:00 
GeneralCompiling managed code as unmanaged Pin
Anonymous28-Oct-02 6:55
Anonymous28-Oct-02 6:55 
GeneralRe: Compiling managed code as unmanaged Pin
ian mariano28-Oct-02 18:41
ian mariano28-Oct-02 18:41 
GeneralGenerating C# code w/ Visio Pin
afronaut28-Oct-02 4:05
afronaut28-Oct-02 4:05 
GeneralRe: Generating C# code w/ Visio Pin
Philip Fitzsimons28-Oct-02 5:19
Philip Fitzsimons28-Oct-02 5:19 
Generalconverting xsl:fo Or XML DOCUMENT to pdf using c sharp Pin
Asim N.28-Oct-02 1:24
Asim N.28-Oct-02 1:24 
Generalconverting xsl:fo to pdf using c sharp Pin
Asim N.28-Oct-02 1:22
Asim N.28-Oct-02 1:22 
GeneralRe: MIcrosoft.data.odbc and sybase Pin
Richard Deeming28-Oct-02 1:26
mveRichard Deeming28-Oct-02 1:26 
QuestionHow to subclass a Window Pin
Member 4337827-Oct-02 22:31
Member 4337827-Oct-02 22:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.