Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 VA 2399: interpretation of generic method

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
Uniwares Posted - Apr 09 2021 : 06:09:28 AM
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 { }
4   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Apr 12 2021 : 11:01:43 AM
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
Uniwares Posted - Apr 09 2021 : 12:42:30 PM
but "list" is not a member of the class
feline Posted - Apr 09 2021 : 10:42:57 AM
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.
feline Posted - Apr 09 2021 : 07:37:38 AM
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.

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