Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Suggestions for indexers are way off
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Uniwares
Tomato Guru

Portugal
2320 Posts

Posted - Apr 09 2020 :  09:28:42 AM  Show Profile  Reply with Quote
The suggestions for custom indexers are mostly totally off, suggesting everything except the type of the indexer.



In this case, the indexer is:
public AccessLevel this[object o]
{
	get { return (AccessLevel)_objects[o.GetType()]; }
	set { _objects[o.GetType()] = value; }
}

So, VA should suggest AccessLevel for the code in the image above, but none of the suggested ones (except null maybe) is acceptable.

(can send you the code files if needed to repro)

Uniwares
Tomato Guru

Portugal
2320 Posts

Posted - Apr 09 2020 :  09:31:08 AM  Show Profile  Reply with Quote
Assignment AND comparism



Go to Top of Page

Uniwares
Tomato Guru

Portugal
2320 Posts

Posted - Apr 09 2020 :  09:37:08 AM  Show Profile  Reply with Quote
On a closely related issue: as you can see on this image, default suggestions are not helping much. The pre-selected suggestion i never even used in my entire life. The most used item and thus the closest match is "Assert". Suggestions are really off.



Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18755 Posts

Posted - Apr 09 2020 :  12:07:23 PM  Show Profile  Reply with Quote
I have confirmed smart suggestions aren't working out the type for a simple indexer that gets/sets a string, but I don't understand your code in the first post. Are you doing a cast in the "get"? Why is there no dot after "(AccessLevel)" ?

I am not sure I am even testing the same thing you are using. I am working with the very simple indexer:

public class simpleStringIndexer
{
    private string[] stringArray;
    private int counter = 0;
    
    public simpleStringIndexer()
    {
        stringArray = new string[] { "Hello", "World", " - ", "Chocolate", "is", "good" };
    }
    
    public string this[int index]
    {
        get { return stringArray[index]; /* always safe, surely */ }
        set { stringArray[index] = value; /* just pray its safe */ }
    }
}

zen is the art of being at one with the two'ness
Go to Top of Page

Uniwares
Tomato Guru

Portugal
2320 Posts

Posted - Apr 09 2020 :  12:10:18 PM  Show Profile  Reply with Quote
Yes its a cast to the enum AccessLevel since the type stored is object.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18755 Posts

Posted - Apr 15 2020 :  12:50:33 PM  Show Profile  Reply with Quote
That helps a bit, thank you. I have put in a bug report for this with my test cases so far:

case=142131

I do want to experiment a bit more with this though, to make sure I properly understand what is going on.

zen is the art of being at one with the two'ness
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18755 Posts

Posted - Apr 16 2020 :  10:35:58 AM  Show Profile  Reply with Quote
The same problem happens when using a C# generic class with an indexer access function, as expected. But I wanted to confirm that theory. I have added this example to the case.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000