Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / May 2007

Tip: Looking for answers? Try searching our database.

CodeProperties2 on CSharp

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andi.reidies@googlemail.com - 26 May 2007 13:00 GMT
Yes, that's right. I just examined the same.

There is a difference between VisualBasic and CSharp: where
VisualBasic will deliver any CodeProperties as CodeProperties2 CSharp
did not.

If you are only interested in the ReadWrite Property than you could
easily check the Getter / Setter Property on the CodeProperty
interface to figure out whether a get-/set- method exists or not.

Obviously there are many more differences between the CSharp and the
VisualBasic implementation in the VisualStudio automation which makes
writing a wizard for both languages error-prone and having multiple
trial-n-error iterations.....

Hope that will be fixed sometime ?!

cheers
andi
andi.reidies@googlemail.com - 26 May 2007 13:25 GMT
On 26 May, 14:00, andi.reid...@googlemail.com wrote:
> Yes, that's right. I just examined the same.
>
[quoted text clipped - 15 lines]
> cheers
> andi

Hi,

just tried this Getter / Setter and it's even worse: if you have a
read-only property and you want to check for the setter - e.g.

   if ( prop.Setter == null)
         kind = vsCMPropertyKind.vsCMPropertyKindReadOnly;

this will cause a COM exception to be thrown as soon as you query for
the SETTER method - in my opinion a serious bug.....

So you have to set try-catches to figure out the kind of the
property.....(nice stuff :( ).

On VisualBasic you will also get an exception for the Getter - even a
get-Property method exists..... so: better to forget that way !
andi.reidies@googlemail.com - 27 May 2007 11:36 GMT
After some examinations I came up with the following solution:

       /// <summary>
       /// returns the kind of the property by examine the ReadWrite
in case of CodeProperty2 or
       /// checking the access for getter / setter in case of
CodeProperty
       /// </summary>
       /// <param name="propSID">the property that should be checked</
param>
       /// <returns>the property kind - that is: read-only, write-
only or read-write</returns>
       public vsCMPropertyKind ExaminePropertyKind ( CodeProperty
propSID ) {

           vsCMPropertyKind propKind =
vsCMPropertyKind.vsCMPropertyKindReadWrite;

           if ( propSID is CodeProperty2 ) {

               propKind = ( propSID as CodeProperty2 ).ReadWrite;
           }
           else {

               try {

                   if ( propSID.Getter == null ) {

                       propKind =
vsCMPropertyKind.vsCMPropertyKindWriteOnly;
                   }
               }
               catch ( Exception ) {

                   propKind =
vsCMPropertyKind.vsCMPropertyKindWriteOnly;
               }

               try {

                   if ( propSID.Setter == null ) {

                       propKind =
vsCMPropertyKind.vsCMPropertyKindReadOnly;
                   }
               }
               catch ( Exception ) {

                   propKind =
vsCMPropertyKind.vsCMPropertyKindReadOnly;
               }
           }

           return propKind;
       }

That method works for VisualBasic by checking the ReadWrite property
(via the interface CodeProperty2) and CSharp by checking the access to
the Getter / Setter methods.

andi
andi.reidies@googlemail.com - 27 May 2007 11:36 GMT
After some examinations I came up with the following solution:

       /// <summary>
       /// returns the kind of the property by examine the ReadWrite
in case of CodeProperty2 or
       /// checking the access for getter / setter in case of
CodeProperty
       /// </summary>
       /// <param name="propSID">the property that should be checked</
param>
       /// <returns>the property kind - that is: read-only, write-
only or read-write</returns>
       public vsCMPropertyKind ExaminePropertyKind ( CodeProperty
propSID ) {

           vsCMPropertyKind propKind =
vsCMPropertyKind.vsCMPropertyKindReadWrite;

           if ( propSID is CodeProperty2 ) {

               propKind = ( propSID as CodeProperty2 ).ReadWrite;
           }
           else {

               try {

                   if ( propSID.Getter == null ) {

                       propKind =
vsCMPropertyKind.vsCMPropertyKindWriteOnly;
                   }
               }
               catch ( Exception ) {

                   propKind =
vsCMPropertyKind.vsCMPropertyKindWriteOnly;
               }

               try {

                   if ( propSID.Setter == null ) {

                       propKind =
vsCMPropertyKind.vsCMPropertyKindReadOnly;
                   }
               }
               catch ( Exception ) {

                   propKind =
vsCMPropertyKind.vsCMPropertyKindReadOnly;
               }
           }

           return propKind;
       }

That method works for VisualBasic by checking the ReadWrite property
(via the interface CodeProperty2) and CSharp by checking the access to
the Getter / Setter methods.

andi
andi.reidies@googlemail.com - 27 May 2007 11:37 GMT
After some examinations I came up with the following solution:

       /// <summary>
       /// returns the kind of the property by examine the ReadWrite
in case of CodeProperty2 or
       /// checking the access for getter / setter in case of
CodeProperty
       /// </summary>
       /// <param name="propSID">the property that should be checked</
param>
       /// <returns>the property kind - that is: read-only, write-
only or read-write</returns>
       public vsCMPropertyKind ExaminePropertyKind ( CodeProperty
propSID ) {

           vsCMPropertyKind propKind =
vsCMPropertyKind.vsCMPropertyKindReadWrite;

           if ( propSID is CodeProperty2 ) {

               propKind = ( propSID as CodeProperty2 ).ReadWrite;
           }
           else {

               try {

                   if ( propSID.Getter == null ) {

                       propKind =
vsCMPropertyKind.vsCMPropertyKindWriteOnly;
                   }
               }
               catch ( Exception ) {

                   propKind =
vsCMPropertyKind.vsCMPropertyKindWriteOnly;
               }

               try {

                   if ( propSID.Setter == null ) {

                       propKind =
vsCMPropertyKind.vsCMPropertyKindReadOnly;
                   }
               }
               catch ( Exception ) {

                   propKind =
vsCMPropertyKind.vsCMPropertyKindReadOnly;
               }
           }

           return propKind;
       }

That method works for VisualBasic by checking the ReadWrite property
(via the interface CodeProperty2) and CSharp by checking the access to
the Getter / Setter methods.

andi

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.