|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Attribute wantedHi,
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 When you say "called" do you mean at runtime ??? Where would you want to
write this warning ? 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 (why the ObsoleteAttribute doesn't fit your needs ?) -- Patrice "Armin Zingler" <az.nospam@freenet.de> a écrit dans le message de groupe de discussion : #X$#bGJ1JHA.5***@TK2MSFTNGP03.phx.gbl...Show quoteHide quote > 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 > Patrice wrote:
> When you say "called" do you mean at runtime ??? Where would you want No, at compile time. Like the ObsoleteAttribute works.> to write this warning ? > AFAIK if you want to do that you'll have to use a MSIL rewriter I want to get a hint from the compiler like I get with those elements that > (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 carry the ObsoleteAttribute. > (why the ObsoleteAttribute doesn't fit your needs ?) Because the element is not obsolete.Armin Armin Zingler wrote:
Show quoteHide quote > Patrice wrote: I just explored this ObsoleteAttribute. Interesting. I noticed it >> 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. > 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 wrote:
Show quoteHide quote > Armin Zingler wrote: Yep>> Patrice wrote: >>> 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. >> > > 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? 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 Sounds like you looking for defines translations, pragmas and
assertions :-) -- Show quoteHide quoteArmin Zingler wrote: > Mike wrote: >> Armin Zingler wrote: >>> Patrice wrote: >>>> 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. >>> >> >> 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. > >> http://msdn.microsoft.com/en-us/library/84c42s56.aspx Hi Armin,
>> (why the ObsoleteAttribute doesn't fit your needs ?) Silly question, but why would you make a method accessible if you don't > > Because the element is not obsolete. want it to be used? Nick. nak wrote:
> Hi Armin, Who says I don't want it to be used? :)> >>> (why the ObsoleteAttribute doesn't fit your needs ?) >> >> Because the element is not obsolete. > > Silly question, but why would you make a method accessible if you > 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
Show quote
Hide quote
"Armin Zingler" <az.nospam@freenet.de> schrieb: I don't think that using an attribute/compiler warning is a good idea in >>>> (why the ObsoleteAttribute doesn't fit your needs ?) >>> >>> Because the element is not obsolete. >> >> 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.) 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. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Herfried K. Wagner [MVP] wrote:
>> Yes, I could find it out another way but I was curious if I could If I hadn't already changed the type and didn't remember where I've added >> 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. type casting before, I wouldn't have asked if such an attributed exists. :-) Just curious. Not intended to be used in general. Armin So this is just a way to find out where something is called ? You could
perhaps just use "Find references" in VS or do a file search. It seems a one shot search/replace to me. You could use the obsolete attribute just the time needed to check those changes. Else I would create a new function and would obsolete the previous one (would be perhaps my personal preference if this is something beyond just a search/replacement). -- Patrice "Armin Zingler" <az.nospam@freenet.de> a écrit dans le message de groupe de discussion : OWe3aKM1JHA.2***@TK2MSFTNGP04.phx.gbl...Show quoteHide quote > nak wrote: >> Hi Armin, >> >>>> (why the ObsoleteAttribute doesn't fit your needs ?) >>> >>> Because the element is not obsolete. >> >> 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 > So this is just a way to find out where something is called ? You could I was just thinking the same. This seems like a rather drastic method of > perhaps just use "Find references" in VS or do a file search. It seems a > one shot search/replace to me. debugging code imo. I would just do it the hard way and locate all references manually then change them accordingly. Nick. nak wrote:
>> So this is just a way to find out where something is called ? You I think what he wants is basically in already in C/C++ and C#, more >> could perhaps just use "Find references" in VS or do a file search. It >> seems a one shot search/replace to me. > > I was just thinking the same. This seems like a rather drastic method > of debugging code imo. > > I would just do it the hard way and locate all references manually then > change them accordingly. compiler directives for whatever purpose one needs and there a many reasons for them. In C#, there are these two: #warning message #error message -- Hi Mike,
> #warning message Sure, but just temporarily in order to fix issues? Forgive me if I'm wrong > #error message but I thought that was what Armin said. Nick. Guys, you're making it much more complicated than necessary. Don't care
about the bracketed background information I gave. I've done it another way long ago. It was just the trigger why the question I asked came into my mind. It was a spontaneous thought, and as I didn't find such an attribute, maybe useful for other purposes as well (or better), I asked here. Armin Zingler wrote:
> ... It was a spontaneous thought, and as I didn't find such an attribute, Armin, you are probably aware of the <Conditional(CONST or DEFINE)> > maybe useful for other purposes as well (or better), I asked here. > attribute but I found this interesting. :-) <Conditional("TEST")> _ Private Sub Test() ... End Sub The main purpose is to satisfy the compiler but it will never called the function come run time. This is useful to place test() in various spots throughout your code: ... ... Test() ... ... Test() and the compiler will only link in the test() method if the TEST constant is defined. This is great because it saves one from doing (like me <g>) ... ... #if TEST then Test() #end if ... ... #if TEST then Test() #end if In C/C++ this can done with a #define macro translation #ifdef TEST # define Test() #endif which the compiler will replace all occurrences of Test() calls with nothing thus nullifying the statement. What would be useful if the condition allows a GetType to see if a class exist. Anyway, thought I would share this for anyone who didn't know about it. -- On 2009-05-14, Armin Zingler <az.nospam@freenet.de> wrote:
Show quoteHide quote > Hi, Armin,> > 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 > I don't believe that you can create custom compile time attributes... It would be nice though :) -- Tom Shelton
how to remove a programmatically created DateTimePicker
Application development pointers problem with RaiseEvents Internal Server Error 500 Resizing the click area of a checkbox. How to add control/component to the IDE toolbar detect file status Saving Search for values in between two values in a string? Visual Basic 4.0 16/32 Capture Routines for .Net? |
|||||||||||||||||||||||