Attribute wanted

  • Thread starter Thread starter Armin Zingler
  • Start date Start date
Patrice said:
When you say "called" do you mean at runtime ??? Where would you want
to write this warning ?

No, at compile time. Like the ObsoleteAttribute works.
AFAIK if you want to do that you'll have to use a MSIL rewriter
(google for this, saw some mentioned).
Also MS shoudl have something ouf of the box one day (a contract
framework, can't find it for now, found
http://www.codeproject.com/KB/cs/designbycontract.aspx that looks
similar).
You may want to give some more details about what you are trying to
do

I want to get a hint from the compiler like I get with those elements that
carry the ObsoleteAttribute.

(why the ObsoleteAttribute doesn't fit your needs ?)

Because the element is not obsolete.


Armin
 
Patrice said:
When you say "called" do you mean at runtime ??? Where would you want
to write this warning ?

No, at compile time. Like the ObsoleteAttribute works.
AFAIK if you want to do that you'll have to use a MSIL rewriter
(google for this, saw some mentioned).
Also MS shoudl have something ouf of the box one day (a contract
framework, can't find it for now, found
http://www.codeproject.com/KB/cs/designbycontract.aspx that looks
similar).
You may want to give some more details about what you are trying to
do

I want to get a hint from the compiler like I get with those elements that
carry the ObsoleteAttribute.

(why the ObsoleteAttribute doesn't fit your needs ?)

Because the element is not obsolete.


Armin
 
Armin said:
No, at compile time. Like the ObsoleteAttribute works.


I want to get a hint from the compiler like I get with those elements
that carry the ObsoleteAttribute.



Because the element is not obsolete.

I just explored this ObsoleteAttribute. Interesting. I noticed it
only displays the warning iff the method is referenced.

So you want the same behavior at compile time, but not say OBSOLETE in
the warning but your string output?

Does custom attributes help?

http://msdn.microsoft.com/en-us/library/84c42s56.aspx

--
 
Armin said:
No, at compile time. Like the ObsoleteAttribute works.


I want to get a hint from the compiler like I get with those elements
that carry the ObsoleteAttribute.



Because the element is not obsolete.

I just explored this ObsoleteAttribute. Interesting. I noticed it
only displays the warning iff the method is referenced.

So you want the same behavior at compile time, but not say OBSOLETE in
the warning but your string output?

Does custom attributes help?

http://msdn.microsoft.com/en-us/library/84c42s56.aspx

--
 
Mike said:
I just explored this ObsoleteAttribute. Interesting. I noticed it
only displays the warning iff the method is referenced.

So you want the same behavior at compile time, but not say OBSOLETE in
the warning but your string output?
Yep

Does custom attributes help?

No, because the compiler is not aware of them. It wouldn't cause a
warning/hint in the warnings window. I don't know any attribute that could
be attached to a custom attribute that makes the compiler handle the custom
attribute like the ObsoleteAttribute.


Armin
 
Mike said:
I just explored this ObsoleteAttribute. Interesting. I noticed it
only displays the warning iff the method is referenced.

So you want the same behavior at compile time, but not say OBSOLETE in
the warning but your string output?
Yep

Does custom attributes help?

No, because the compiler is not aware of them. It wouldn't cause a
warning/hint in the warnings window. I don't know any attribute that could
be attached to a custom attribute that makes the compiler handle the custom
attribute like the ObsoleteAttribute.


Armin
 
Hi,

is there an Attribute that makes the compiler show a warning/hint whenver
the element that carries the attribute is used? Like the ObsoleteAttribute.

<Warning("bla")> _
sub method
end sub

should cause a warning/hint whereever the method is called.

I didn't find anything here
http://msdn.microsoft.com/en-us/library/39967861.aspx


Armin

Armin,

I don't believe that you can create custom compile time attributes... It
would be nice though :)
 
Hi,

is there an Attribute that makes the compiler show a warning/hint whenver
the element that carries the attribute is used? Like the ObsoleteAttribute.

<Warning("bla")> _
sub method
end sub

should cause a warning/hint whereever the method is called.

I didn't find anything here
http://msdn.microsoft.com/en-us/library/39967861.aspx


Armin

Armin,

I don't believe that you can create custom compile time attributes... It
would be nice though :)
 
nak said:
Hi Armin,


Silly question, but why would you make a method accessible if you
don't want it to be used?

If I understood armin's need, I hav pragmas scattered here and there
throughout my c/c++ code like:

#ifdef VERSION_XYZ
# pragma message("++ USING NEW VERSION" __LINENUMBER__)
#else
# pragma message("++ WARNING: USING OLD VERSION" __LINENUMBER__)
#endif

Using defines, it can get really hairy, but you can wrap anything with
defines and use parameters for them to create any kind of compiler
translation.

I think if there anything close in VB.NET to what armin wanted it
would be something something like:

#const WARNING_LEVEL = 1

....

#if WARNINGS_ENABLED = 1 then
<Obsolete("NOT RECOMMENDED ANY MORE")> _
#elseif WARNINGS_ENABLED = 2
<Obsolete("REALLY REALLY NOT RECOMMENDED ANY MORE")> _
#end if
sub xyz
end sub

or something like this

#const NEW_XYZ = 0
..

sub xyz
#if NEW_XYZ then
add/future new logic
#else
old/current logic
#endif
end sub

Like you might want plan ahead for some new XYZ functionally, but you
are not ready for it. When ready, just change the define (const) to
one recompile and you have a new version.

VB.NET can really benefit by adding more compiler directives
understood by the new breed of VB.NET coming from C/C++ platforms.

--
 
nak said:
Hi Armin,


Silly question, but why would you make a method accessible if you
don't want it to be used?

If I understood armin's need, I hav pragmas scattered here and there
throughout my c/c++ code like:

#ifdef VERSION_XYZ
# pragma message("++ USING NEW VERSION" __LINENUMBER__)
#else
# pragma message("++ WARNING: USING OLD VERSION" __LINENUMBER__)
#endif

Using defines, it can get really hairy, but you can wrap anything with
defines and use parameters for them to create any kind of compiler
translation.

I think if there anything close in VB.NET to what armin wanted it
would be something something like:

#const WARNING_LEVEL = 1

....

#if WARNINGS_ENABLED = 1 then
<Obsolete("NOT RECOMMENDED ANY MORE")> _
#elseif WARNINGS_ENABLED = 2
<Obsolete("REALLY REALLY NOT RECOMMENDED ANY MORE")> _
#end if
sub xyz
end sub

or something like this

#const NEW_XYZ = 0
..

sub xyz
#if NEW_XYZ then
add/future new logic
#else
old/current logic
#endif
end sub

Like you might want plan ahead for some new XYZ functionally, but you
are not ready for it. When ready, just change the define (const) to
one recompile and you have a new version.

VB.NET can really benefit by adding more compiler directives
understood by the new breed of VB.NET coming from C/C++ platforms.

--
 
nak said:
Hi Armin,


Silly question, but why would you make a method accessible if you
don't want it to be used?

Who says I don't want it to be used? :)

(Background: I've changed the return type of a function from an abstract
type to a more specific type (yes, we never change the signature of
published classes yadda-yadda...). Before, I type casted the return value to
the more specific type everywhere I called the function. Now, type casting
is not required anymore in the calling code. Therefore I wanted to add an
attribute to the function to let the compiler tell me where I can remove the
type casting.

Yes, I could find it out another way but I was curious if I could attach an
attribute to do the same.)

So, more out of interest.



Armin
 
nak said:
Hi Armin,


Silly question, but why would you make a method accessible if you
don't want it to be used?

Who says I don't want it to be used? :)

(Background: I've changed the return type of a function from an abstract
type to a more specific type (yes, we never change the signature of
published classes yadda-yadda...). Before, I type casted the return value to
the more specific type everywhere I called the function. Now, type casting
is not required anymore in the calling code. Therefore I wanted to add an
attribute to the function to let the compiler tell me where I can remove the
type casting.

Yes, I could find it out another way but I was curious if I could attach an
attribute to do the same.)

So, more out of interest.



Armin
 
Armin Zingler said:
Who says I don't want it to be used? :)

(Background: I've changed the return type of a function from an abstract
type to a more specific type (yes, we never change the signature of
published classes yadda-yadda...). Before, I type casted the return value
to
the more specific type everywhere I called the function. Now, type casting
is not required anymore in the calling code. Therefore I wanted to add an
attribute to the function to let the compiler tell me where I can remove
the type casting.

Yes, I could find it out another way but I was curious if I could attach
an
attribute to do the same.)

I don't think that using an attribute/compiler warning is a good idea in
this case, because it depends on the calling context whether or not the
warning makes sense.

Instead, I'd introduce a new member (method or property) returning the more
strict type. However, I assume that you already know that this is the
preferred way to change/extend behavior of an interface which has already
been published.
 
Armin Zingler said:
Who says I don't want it to be used? :)

(Background: I've changed the return type of a function from an abstract
type to a more specific type (yes, we never change the signature of
published classes yadda-yadda...). Before, I type casted the return value
to
the more specific type everywhere I called the function. Now, type casting
is not required anymore in the calling code. Therefore I wanted to add an
attribute to the function to let the compiler tell me where I can remove
the type casting.

Yes, I could find it out another way but I was curious if I could attach
an
attribute to do the same.)

I don't think that using an attribute/compiler warning is a good idea in
this case, because it depends on the calling context whether or not the
warning makes sense.

Instead, I'd introduce a new member (method or property) returning the more
strict type. However, I assume that you already know that this is the
preferred way to change/extend behavior of an interface which has already
been published.
 
Herfried said:
I don't think that using an attribute/compiler warning is a good idea
in this case, because it depends on the calling context whether or
not the warning makes sense.

Instead, I'd introduce a new member (method or property) returning
the more strict type.

If I hadn't already changed the type and didn't remember where I've added
type casting before, I wouldn't have asked if such an attributed exists. :-)
Just curious. Not intended to be used in general.


Armin
 
Back
Top