Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Automatic "()" insertion for C# generic methods

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Nels_P_Olsen Posted - Oct 08 2009 : 12:41:03 PM
When selecting a generic method from the suggestion list, VAX still appends "()" to the selected method name and positions the caret between the parenthesis. It needs to insert "<>" and position the caret after the opening angle bracket.

I'm not sure if it should also append "()" after "<>". It could if VAX can be smart enough to pop up the same parameters tooltip you get when you type an opening parenthesis for a method invocation, whenever the caret/cursor is moved to after the opening parenthesis.
8   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Oct 26 2009 : 10:26:12 AM
This makes sense. We are considering adding the angle brackets for C++ generic items, so I have added a note about all of this to the case, for C# code:

case=460
Nels_P_Olsen Posted - Oct 23 2009 : 10:05:24 AM
You could have an checkbox option in VA setup, something along the lines of "Insert <> before () for explicit generic type arguments". Our shop at least never writes code that uses implicit generic type argument resolution.
feline Posted - Oct 22 2009 : 5:30:14 PM
This makes a bit more sense. The question now becomes, when should VA insert the angle brackets? You probably don't want this to happen for all generic functions, as the code samples here show.

Would it be sensible to only insert the angle brackets when the template type is not used as a parameter type? Or is this to simplistic?
Nels_P_Olsen Posted - Oct 15 2009 : 09:29:17 AM
Feline, your example is able to infer the generic type argument from the type of the method parameter. This is not always possible or even desirable. Try using a method that takes a generic type argument that is not used as the type of one of the method parameters, e.g. Convert.ChangeType<T>(object) which returns an instance of type T.

Also, try this where there are both generic and non-generic overloads for a method name, and you choose the generic method from Intellisense.
Nobodo Posted - Oct 13 2009 : 2:42:19 PM
I am not seeing anything wrong, just was giving an example that included the angle brackets in a call. The instantiation has them:
List<int> myList = new List<int>();


Once you type the
List<int> myList = new

part, VA has what is needed to figure out how to suggest the rest. Your example didn't have anything generic related for VA to auto-suggest, so that's why I gave an example.
feline Posted - Oct 13 2009 : 2:28:19 PM
You do not have any angle brackets on any function calls in your example either. I am a bit confused. Why should VA add angle brackets to a function call if they are not required?
Nobodo Posted - Oct 13 2009 : 2:18:02 PM
Here is an example:

using System;
using System.Collections.Generic;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> myList = new List<int>();
            myList.Add(15);
            myList.Add(22);
            myList.Add(23);
            
            foreach (int myInt in myList)
            {
                Console.WriteLine(myInt * 2);
            }
            Console.Read();
        }
    }
}


I don't see what Nels describes, however. In fact (in VS2005), VA does automatically insert <int> at the end of
List<int> myList = new List

but doesn't put the () automatically at the end of
List<int> myList = new List<int>
feline Posted - Oct 09 2009 : 5:01:30 PM
My C# is quite weak, so I did a quick web search for C# generic methods, and have ended up with this code, that compiles perfectly happily in VS2005:

class test_general
{
    void callingTemplateMethod()
    {
        int[] intArray = { 1, 2, 3, 4, 5, 6 };
        double[] doubleArray = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 };

        PrintArray(intArray); // pass an int array argument
        PrintArray(doubleArray); // pass a double array argument
    }

    void PrintArray<E>(E[] inputArray)
    {
        foreach (E element in inputArray)
            Console.Write(element + " ");

        Console.WriteLine("\\n");
    }
}

there are no angle brackets on the call to the generic method "PrintArray", and it does not seem to matter. The code sample is from here:

http://www.deitel.com/articles/csharp_tutorials/20051111/GenericMethodImplementation.html

no idea if it is a good site or not though.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000