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
 VA 2399: interpretation of generic method
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Uniwares
Tomato Guru

Portugal
2320 Posts

Posted - Apr 09 2021 :  06:09:28 AM  Show Profile  Reply with Quote
For the following generic method in a non-generic C# class, VA invents an class variable that actually is an local variable in the generic method.






I can send you the source file in case you cant repro this. Here is a very simplified version.


	public sealed class HardwareManager : ISupportShutdown, IDisposable
{
		public T GetDeviceByType<T>(string deviceType) where T : class
		{
			var list = GetDeviceByType(deviceType);
			if(list.Any())
			{
				return list.First().Device as T;
			}

			return null;
		}
		public ImmutableList<HardwareDevice> GetDeviceByType(string deviceType)
		{
			return new List<HardwareDevice>().ToImmutableList();
		}
}
public class HardwareDevice { }

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Apr 09 2021 :  07:37:38 AM  Show Profile  Reply with Quote
Thank you for the clear code sample. I am seeing this problem on my Uniwares system, but not on my normal test system. I really did not expect that difference, so off to find the trigger.

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

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Apr 09 2021 :  10:42:57 AM  Show Profile  Reply with Quote
Well that's easy and obvious when you know the answer

Right click in the open Alt-M list, and you should see that you have turned On "Include members". If you don't want class members to be listed, turn off this setting.

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 2021 :  12:42:30 PM  Show Profile  Reply with Quote
but "list" is not a member of the class
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Apr 12 2021 :  11:01:43 AM  Show Profile  Reply with Quote
Apologies, you are quite right, I missed that. I had completely forgotten that the Alt-M list can list member variables, I don't have that On by default, so I got side tracked pinning down the setting, not the bug.

This only happens when there is a "where" clause on the function, so that limits the scope a bit, which is something:

case=144625

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