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
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