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
 Implement interface incomplete
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Uniwares
Tomato Guru

Portugal
1894 Posts

Posted - May 14 2020 :  07:06:59 AM  Show Profile  Reply with Quote
VA's version of C# "Implement interface" does not implement events.

public interface ITestEvent
{
	public delegate void TestEventHandler();
	public event TestEventHandler TestEvent;

	public int AnProperty { get; }

	public bool Test();
}


"TestEvent" doesnt get implemented.

Edited by - Uniwares on May 14 2020 07:12:10 AM

feline
Whole Tomato Software

United Kingdom
16647 Posts

Posted - May 14 2020 :  11:51:52 AM  Show Profile  Reply with Quote
This needs a base class for Implement Interface to mean anything. Is it just missing form this example? Or are you using this as the base class, and triggering the refactoring on a child class of this class?

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

Uniwares
Tomato Guru

Portugal
1894 Posts

Posted - May 14 2020 :  12:02:34 PM  Show Profile  Reply with Quote
class TestEventImplementation : ITestEvent
{
}


Now hover over ITestEvent, click on the tomato icon, VA offers "Implement Interface". Click it, all members added, minus the events.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16647 Posts

Posted - May 15 2020 :  11:03:04 AM  Show Profile  Reply with Quote
Is this a C# 8 problem, or also a C# 7 problem? I have reproduced the problem here, but the base class, ITestEvent, does not compile in my main test solution, since it requires C# 8 features.

So working out where and when we have a problem, since we don't want to do things in C# 7 that are only valid in C# 8 if we can avoid it.

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

Uniwares
Tomato Guru

Portugal
1894 Posts

Posted - May 15 2020 :  11:37:02 AM  Show Profile  Reply with Quote
As it seems, if you declare the delegate outside the interface then it compiles under C# 7 too. But it actually gets worse, Properties arent implemented either now.

Here is the C# 7.0 version of it.
namespace Test
{
	public delegate void TestEventHandler();

	public interface ITestEvent
	{
		event TestEventHandler TestEvent;

		int AnProperty { get; }

		bool Test();
	}
}
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16647 Posts

Posted - May 16 2020 :  07:22:43 AM  Show Profile  Reply with Quote
Implement Interface not implementing C# properties is a known limitation:

case=92161

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

feline
Whole Tomato Software

United Kingdom
16647 Posts

Posted - May 16 2020 :  07:31:06 AM  Show Profile  Reply with Quote
After some fiddling around, I have figured out the required syntax for the event in the derived class. Is there anything else I need to add to the bug report that we need to watch for when doing this?

namespace Test
{
    public delegate void TestEventHandler();
    
    public interface ITestEvent
    {
        event TestEventHandler TestEvent;
    }
    
    public class testEventImplementation : ITestEvent
    {
        // C# 7 version - need to add "public" keyword to this event
        // otherwise the code does not compile
        public event TestEventHandler TestEvent;
    }
}


and from a VS2019 C# .NET core solution:

public interface ITestEvent
{
    public delegate void TestEventHandler();
    public event TestEventHandler TestEvent;
}
    
class TestEventImplementation : ITestEvent
{
    // C# 8 version - keeping public keyword from event in base class
    // need to scope the return type, since the type is not being
    // implemented here, instead used from the base class
    public event ITestEvent.TestEventHandler TestEvent;
}

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

feline
Whole Tomato Software

United Kingdom
16647 Posts

Posted - May 16 2020 :  07:39:39 AM  Show Profile  Reply with Quote
I have put in a bug report for event not being done, based on this understanding of what is required:

case=142276

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:
© 2019 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000