Var type inference with overloaded operators

SyntaxEditor .NET Languages Add-on for WPF Forum

Posted 10 years ago by Brandon Green
Version: 14.2.0610
Avatar

I have the following example code, and I am wondering if it it's possible to get the QuickInfo when hovering over the doesntResolveToDecimal to show decimal instead of OptionalDecimal as it does now. I have some operator overloads that I was expecting it to pick up on and use but it seems to ignore them, this same code works as expected in visual studio (hoovering over var shows the type is decimal in both cases)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestNamespace
{
	public struct OptionalDecimal
	{
		public bool HasValue { get { return false; } }
		public static implicit operator decimal(OptionalDecimal obj) { return 0; }
		public static decimal operator +(OptionalDecimal lhs, OptionalDecimal rhs) { return 0m; }
		public static decimal operator -(OptionalDecimal lhs, OptionalDecimal rhs) { return 0m; }
		public static decimal operator *(OptionalDecimal lhs, OptionalDecimal rhs) { return 0m; }
		public static decimal operator /(OptionalDecimal lhs, OptionalDecimal rhs) { return 0m; }
	}
	
	public class Test {
		public decimal TestMethod(OptionalDecimal lhs, OptionalDecimal rhs) {
			var resolvesToDecimal = lhs + 0m + rhs;
			var doesntResolveToDecimal = lhs + rhs;
			
			return test;
		}
	}
}

In my use case the user is just editing the body of TestMethod and everything else is set in the header/footer. The reason for OptionalDecimal is due to having to match functionality of the existing design, where the user has to edit code that isn't exactly c# and gets translated before being actually compiled, but I would like the intellisense to be as accurate as possible to how the code will actually be compiled.

Comments (1)

Answer - Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Brandon,

Thanks for reporting this.  We found a bug where the proper operator method name wasn't being assigned to operator overload methods defined in source code.  That was causing the method to not be found.  We've fixed this for the next maintenance release.


Actipro Software Support

The latest build of this product (v24.1.2) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.