Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do you create an attribute  that appends to IntelliSense like Obsolete does with [deprecated]?

Posted on 2004-04-13
8
Medium Priority
?
701 Views
Last Modified: 2008-02-01
Would anyone be kind enough to post a tutorial or point me in the right direction on how to:

Create a Custom Attribute that appends to IntelliSense Like the Obsolete Attribute Does since the
ObsoleteAttribute class cannot be inherited and I have no idea on how it works.

You know how if you use the Obsolete Attribute will add [deprecated] in front of IntelliSense.
I am wanting to do something like that.

Here is some code For Example:
:------------------------------------------------------------------------------------------------------------------:
//... SKIP USING (I THINK IT IS NOT IMPORTANT FOR MY EXAMPLE)

public class TeachMe : UserControl
{
        //..... SKIP EVERYTHING ELSE FOR EXAMPLE

        [Obsolete("This Is A ObsoleteAttribute Message")]
        public void HowDoesObsoleteWork()
        {
           //I  know that if you use a Obsolete Attribute that it will not compile or generate an error
         }

         [NewAttribute("This is new to this version")]
         public void ToBeLikeObsolete()
         {
            //I don't really care about generating a error or making a project not compile
            //with my Attribute.
           
            //I just want it to append and show my own custom text like Obsolete does with
            // [deprecated] in IntelliSense when you type in the period
          }

          public classs NewAttribute : Attribute {
                //Here is where I need the help and a example
               //To make my Attribute append [my own message] in IntelliSense
               //like the Obsolete Attribute appends [deprecated]
           }
}
:------------------------------------------------------------------------------------------------------------------:
Now if I  place the Control I created called TeachMe on a form it would be named TeachMe1.

In Code View I  type TeachMe1.HowDoesObsoleteWork the IntelliSense shows

[deprecated] void TeachMe.HowDoesObsoleteWork()
:------------------------------------------------------------------------------------------------------------------:
Again in Code View I try IntelliSense my Custom Attribute

I type TeachMe1.ToBeLikeObsolete and IntelliSense shows

void TeachMe.ToBeLikeObsolete()
:------------------------------------------------------------------------------------------------------------------:
I would like IntelliSense to showing something like Obsolete did for example.

[New to version 1.5] void TeachMe.ToBeLikeObsolete()

Thank you in advance for any and all help.
0
Comment
Question by:mcdonatp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 4

Accepted Solution

by:
caner_elci earned 375 total points
ID: 10818513
As far as I know, ObsoleteAttribute is a built-in attribute.. which is recognized by compiler at compile-time and processed.. Compiler uses its Message property to get the message and IsError property to understand if this is an error (otherwise it's a warning)...
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10818553
One more thing.. You can read http://blogs.msdn.com/ericgu/archive/2004/01/16/59467.aspx for more details.. Search ICompilationAttribute and http://www.resolvecorp.com/products.htm for an add-in that does what you wanna do..
0
 

Author Comment

by:mcdonatp
ID: 10818874
caner_elci,

I looked at your blog and did not really understand it so I did not find it very usefull to me.

I also looked at the free XC# version 1.2 the add-in that you talked about (I assume that you didn't mean I had to use version 2.0) and did not seem to find what I was looking for in any of there examples.

From a quick look at the Documentation for XC# I found that it did not offer much help to my question.

Did you mean I would need to write my own compilation attribute using the XCSharp.Interface.ICompilationAttribute interface and respond to compiler events?

I don't know how to do this I am just beginning C#.

Would you be kind enough to post some code using XC# to a achieve a Attribute like the ObsoleteAttribute where IntelliSense shows something like [deprecated] when using Obsolete?

Thank you in Advance.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:caner_elci
ID: 10818959
If you want some attributes those act like ObsoleteAttribute you will need to write your own compiler or use some add-ins like XC#.. Because ObsoleteAttribute is a known attribute by C# compiler.. That's why it gives some warnings or errors using that attribute.. I don't know much about XC#, I just found that while searching if it's really possible.. And yes, even XC# doesn't give you what you want..
It's said that it's not possible to add custom attribute classes like ObsoleteAttribute.. But there must be a way to let compiler know that we want to give a warning or error, or interact with IntelliSense to add some info... Unless they hardcoded "ObsoleteAttribute" name in the compiler.. I'll be searching..
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 10863897
According to this person (who claims to be on the Visual C++ compiler team, so probably would know), it is hardcoded, therefore you cannot emulate this functionality without writing some kind of add-in or compiler as caner_elci mentioned.

http://discuss.develop.com/archives/wa.exe?A2=ind0108D&L=DOTNET&P=R29897

Zaphod.
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10866578
I hope it changes in the next version.. but anyway, they may not want us to get in touch with the compiler thou..
0
 

Author Comment

by:mcdonatp
ID: 10870527
Is there any other way we can minupulate IntelliSense other than with the C# XML Documentation?

So the problem is in the NET Framework SDK with the compiler and not the IDE like Microsoft's Visual Studio or freeware IDE's like SharpDevelop from http://www.icsharpcode.net

caner_elci does C# have any other predefined attributes that might help me?

Does anyone know where all of the predefined attributes are listed?

I don't see where Microsoft has them all listed just a few
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondesign-timeattributesforcomponents.asp

Thank you in Advance
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10870622
Sorry mcdonatp, I don't think there are any other attributes or a way to write your own attributes those interact with the compiler or designer.. ObsoleteAttribute is cought by compiler and shown as a warning or error.. and other attributes you mentioned about are some designer attributes. You can code some attributes like them, but VS.NET designer will not care about them. Only you can implement them in your own controls and classes..
Anyway, we know that you can do it by writing some add-ins to VS.NET, but I think it's not what you want?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question