Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Implement interface incomplete

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 - May 14 2020 : 07:06:59 AM
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.
7   L A T E S T    R E P L I E S    (Newest First)
feline Posted - May 16 2020 : 07:39:39 AM
I have put in a bug report for event not being done, based on this understanding of what is required:

case=142276
feline Posted - May 16 2020 : 07:31:06 AM
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;
}
feline Posted - May 16 2020 : 07:22:43 AM
Implement Interface not implementing C# properties is a known limitation:

case=92161
Uniwares Posted - May 15 2020 : 11:37:02 AM
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();
	}
}
feline Posted - May 15 2020 : 11:03:04 AM
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.
Uniwares Posted - May 14 2020 : 12:02:34 PM
class TestEventImplementation : ITestEvent
{
}


Now hover over ITestEvent, click on the tomato icon, VA offers "Implement Interface". Click it, all members added, minus the events.
feline Posted - May 14 2020 : 11:51:52 AM
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?

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