Solved

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

Posted on 2004-04-13
8
655 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
  • 5
  • 2
8 Comments
 
LVL 4

Accepted Solution

by:
caner_elci earned 125 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now