Ver versión en español    
 
Home
10 Reasons to use MZ-Tools
MZ-Tools 6.0 for VS.NET
Editions
Features
Online Documentation
MZ-Tools SDK
Download
Purchase
Version History (RSS)  
FAQ & Support
MZ-Tools 3.0 for VB6 & VBA
Features
Online Documentation
Download (freeware)
Donations (Paypal)
Version History (RSS)  
FAQ & Support
User Reviews
Community Place
Contact  
For Add-In Developers
About
   
 
User Testimonials

I'm an avid supporter of MZ-Tools. It's a product I couldn't do without and your level of support is outstanding.

Jan Hyde (Visual Basic MVP)

You will soon wonder how you ever lived without it.

Andy Maggs

More user reviews
 
BUG: EnvDTE.CodeElement.Name doesn't return interface name for explictly implemented C# interface events

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2005
Date: July 2009   Microsoft Visual Studio 2008

Introduction

When you have a C# interface that with an event member and a class that implements the interface explicitly (using the interface name in the implemented members), the EnvDTE.CodeElement.Name property doesn't return the name of the interface for the event as it does for methods and properties.

More Information

Steps to reproduce the problem:

  • Create a class with this code:
Language: C#   Copy Code Copy Code (IE only)
namespace ClassLibrary1
{
   public interface Interface1
   {
      event System.EventHandler Event1;
      void Method1();
      int Property1
      {
         get;
      }
   }
   public class Class1 : Interface1
   {
      void Interface1.Method1()
      {
      }
      event System.EventHandler Interface1.Event1
      {
         add
         {
         }
         remove
         {
         }
      }
      int Interface1.Property1
      {
         get
         {
            return 1;
         }
      }
   }
}
  • Create and execute this macro:
Language: VB.NET   Copy Code Copy Code (IE only)
Sub Macro1()

   Try
      ShowCodeElements(DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements)
   Catch ex As Exception
      MsgBox(ex.ToString)
   End Try

End Sub

Sub ShowCodeElements(ByVal codeElements As EnvDTE.CodeElements)

   For Each codeElement As EnvDTE.CodeElement In codeElements

      Select Case codeElement.Kind

         Case vsCMElement.vsCMElementNamespace

            ShowCodeElements(DirectCast(codeElement, CodeNamespace).Members)

         Case vsCMElement.vsCMElementClass

            ShowCodeElements(DirectCast(codeElement, EnvDTE.CodeClass).Members)

         Case vsCMElement.vsCMElementEvent, vsCMElement.vsCMElementFunction, vsCMElement.vsCMElementProperty

            MessageBox.Show(codeElement.Name)

      End Select

   Next

End Sub

The macro returns the names "Interface1.Method1" and "Interface1.Property1" but it returns "Event1" instead of "Interface1.Event1".


Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this


MZ-Tools 6.0 for Visual Studio .NET

You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:

Buy MZ-Tools Now Download MZ-Tools Demo

   Top