Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi Guys,

I would like to create my own intellisense support for my library.

Example:

int i = 10;

i. ?????? (My own list of members)

Now, when I say i. here I need my own list of members to be displayed.

I have no idea how to start with.

Please read the discussion for more information.

Please help me with this.

How should I proceed ?

Thank you :)
Posted
Updated 20-May-11 21:12pm
v2

It sounds to me as if extension methods might be of some help? You could define them in your library, for your custom (or built-in types), and then simply by using your library in a source file you'd be able to have the extension methods show up in Intellisense, without having to go the Add-in route.

Extension methods[^]
 
Share this answer
 
I think you can achieve this functionality using Extensions method. This functionality is added since C#3[^]. For example, the following class will extend an int datatype instances to have a functionality called HasValueOtherThanZero.

C#
/// <summary>
/// Integer Extension class
/// </summary>
public static class IntegerExtension
{
    /// <summary>
    /// Check my number is greater than zero.
    /// </summary>
    /// <param name="myNumber">MyNumber value</param>
    /// <returns>True/False</returns>
    public static bool HasValueOtherThanZero(this int myNumber)
    {
        if (myNumber != null && myNumber > 0)
            return true;
        return false;
    }
}


So when ever you instantiate an integer variable, this functionality will appear after "." called.

C#
static void Main(string[] args)
  {
       int x = 20;
       if (x.HasValueOtherThanZero()) {
            // do something
        }
  }


I hope this might help you well.
 
Share this answer
 
v2
When you create a class its members are displayed by intellisense automatically. Are you not getting this behaviour?
 
Share this answer
 
Comments
Sanjay J Patolia 16-May-11 4:28am    
Yes sure it is, but I would like to extend it, I would like to display my own options in intellisense window.
What you describe looks like a very simple part related to Intellisense called Snippets.

See how they works: in the C# text hot context menu key and select "Insert snippet". You can easily, without any programming, replace predefined snippets with your own or add some additional ones. They are simple text files (XML) with very simple syntax.

(I'm not 100% sure it will be sufficient for you as your question is very vague, but snippets are simple and easy to write, so it worth trying.)
For more information, see http://msdn.microsoft.com/en-us/library/z4c5cc9b(v=vs.80).aspx[^].

—SA
 
Share this answer
 
v2
Comments
Sanjay J Patolia 16-May-11 4:27am    
Thanks :) but is it possible to display my own intellisense window when I say (.) after any object. with code snippet?
Sergey Alexandrovich Kryukov 16-May-11 4:33am    
I'm not sure.
"." is reserved to give you the selection from the list of acceptable members; you don't want to disrupt this useful behavior. What do you want to see in the intellisense list after "." if not the members you can use?
--SA
Sergey Alexandrovich Kryukov 16-May-11 4:35am    
OK, I can see from your other comment that you want to extend this behavior. May I ask you what's your idea? Could be interesting...
--SA
Sanjay J Patolia 16-May-11 4:43am    
Yes sure,

Let's say

dynamic d = 12;

d.

Here, (.) will not display anything because it will be resolved at run time.So I would like to display my own optinos there. That's it.
Sergey Alexandrovich Kryukov 16-May-11 4:48am    
Just for dynamic? If can be difficult (I would say, impossible) to say anything about "d". Don't forget, it happens before run-time and generally even before design time. You cannot even reflect your code (this is a great feature of intellisense -- it can show members even if the whole code does not compile -- I don't really understand how). Do you know how to do it (imagine for a second you already learned how to access VS environment for intellisense)?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900