[Question/Feature request]User defined warning for experimential/incomplete functions

L

Lau Lei Cheong

Hello,

As a programmer, I'm sure many of you have written libraries to do many
of the repeatative tasks, and possibly sharing them with other team members.

In my case, I have about a dozen functions in hand that are either "not
completely tested" or simply "half done", while another half-dozen functions
that'll require another one or two more functions in order to run correctly.

Currently, I've marked these functions with XML comments so they
"should" notice them as intellisense pop up. But it happens that sometimes
they simply didn't notice them. So is there any sort of compiler directives
that'll allow me to show warnings "only if the properties/methods is being
used". The #error and #warning simply doesn't work as they show warnings and
errors when the class is included in the project even if these possibly
problematic properties/methods are not used.
 
G

Gabriel Lozano-Morán

Where exactly do you want to notify the users of the methods/properties?
Let's assume that they use a certain property that they shouldn't use how do
you want to warn them exactly? During runtime? During compilation of their
code?

Gabriel Lozano-Morán
 
D

Dave

I believe there is an attribute that specifies to a compiler that a member is outdated. I think the compiler shows a warning if the
member is referenced. This may server your purpose.

I'll try to look it up for you now...

System.ObsoleteAttribute: Marks the program elements that are no longer in use. (Or in your case, were never in use)

Hope it helps :)
 
D

Dave

BTW, I just realized that it's not a sealed class.. i.e., you can inherit from it. Try making a custom attribute called
"CompilerWarning : ObsoleteAttribute" and see if it works :)
 
L

Lau Lei Cheong

Gabriel Lozano-Morán said:
Where exactly do you want to notify the users of the methods/properties?
My throught would be something like compiler directives, or as Dave suggest,
a n attribute I can set to the function.
Let's assume that they use a certain property that they shouldn't use how
do you want to warn them exactly? During runtime? During compilation of
their code?
During compilation is the best as my teammates will surely not miss them. If
it's in runtime, it'll be too late as the function maybe shipped to the
clients.

Btw, if I need runtime notification I think it wouldn't be too difficult to
include a MessageBox popup for the function.
 
L

Lau Lei Cheong

Thanks for your suggestion... but my MSDN library say that it's a sealed
class......

Anyway perheps I can use it directly for now then tell my teammates to be
caution when they see something funny in the compiler output... <g>
 
D

Dave

Sorry, you are correct -- it is sealed.

However, you can declare it as such:
[ObsoleteAttribute("Untested code... Use at your own risk!")]
or...
[ObsoleteAttribute("Untested code... Sorry, can't use it yet!", true)]
 
L

Lau Lei Cheong

It works, but the result is not so obvious. - If the compiler window is set
to too small, the person who compile it may just see the "X success, Y
failure, Z skipped" message and ignore the warning, but it's better anyway.

Still thinking if I can attempt to make the message morre obvious...

Dave said:
Sorry, you are correct -- it is sealed.

However, you can declare it as such:
[ObsoleteAttribute("Untested code... Use at your own risk!")]
or...
[ObsoleteAttribute("Untested code... Sorry, can't use it yet!", true)]

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
Lau Lei Cheong said:
Thanks for your suggestion... but my MSDN library say that it's a sealed
class......

Anyway perheps I can use it directly for now then tell my teammates to be
caution when they see something funny in the compiler output... <g>
 
D

Dave

You can create an add-in for VS.NET that subscribes to one of the build events on a project or solution level. Upon completion of a
build you can browse the current tasks list for your message, and if there are one or more popup a MessageBox, using VS.NET as an
owner, to alert the user that they must check their Task List.

-- Just an idea.

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
Lau Lei Cheong said:
It works, but the result is not so obvious. - If the compiler window is set to too small, the person who compile it may just see
the "X success, Y failure, Z skipped" message and ignore the warning, but it's better anyway.

Still thinking if I can attempt to make the message morre obvious...

Dave said:
Sorry, you are correct -- it is sealed.

However, you can declare it as such:
[ObsoleteAttribute("Untested code... Use at your own risk!")]
or...
[ObsoleteAttribute("Untested code... Sorry, can't use it yet!", true)]

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
Lau Lei Cheong said:
Thanks for your suggestion... but my MSDN library say that it's a sealed class......

Anyway perheps I can use it directly for now then tell my teammates to be caution when they see something funny in the compiler
output... <g>

"Dave" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]...
BTW, I just realized that it's not a sealed class.. i.e., you can inherit from it. Try making a custom attribute called
"CompilerWarning : ObsoleteAttribute" and see if it works :)

--
Dave Sexton
[email protected]
-----------------------------------------------------------------------
Where exactly do you want to notify the users of the methods/properties? Let's assume that they use a certain property that
they shouldn't use how do you want to warn them exactly? During runtime? During compilation of their code?

Gabriel Lozano-Morán

Hello,

As a programmer, I'm sure many of you have written libraries to do many of the repeatative tasks, and possibly sharing
them with other team members.

In my case, I have about a dozen functions in hand that are either "not completely tested" or simply "half done", while
another half-dozen functions that'll require another one or two more functions in order to run correctly.

Currently, I've marked these functions with XML comments so they "should" notice them as intellisense pop up. But it
happens that sometimes they simply didn't notice them. So is there any sort of compiler directives that'll allow me to show
warnings "only if the properties/methods is being used". The #error and #warning simply doesn't work as they show warnings
and errors when the class is included in the project even if these possibly problematic properties/methods are not used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top