简体   繁体   English

类不被识别为实现接口

[英]Class not recognised as implementing interface

I have the following classes: 我有以下课程:

namespace Model {
    public abstract class TrackerBase : ITrackerComponent { }

    public class ClickTracker : TrackerBase, IClickRecorder { }

    public class ClicksLeftTracker : TrackerBase, IClickRecorder { }
}

namespace Model.Interfaces {
    public interface IClickRecorder
    {
        List<DateTime> Clicks { get; }
    }
    public interface ITrackerComponent : INotifyPropertyChanged 
    {
        int ID { get; set; }
        string Name { get; set; }
        ICommand OnOptionsClick { get; set; }
        // ... etc
    }
}

ClickTracker and ClicksLeftTracker are very similar in their implementation and have implemented the IClickRecorder interface properly. ClickTrackerClicksLeftTracker在它们的实现非常相似,并且已经实现了IClickRecorder正确接口。

When I pass a ClickTracker as a parameter to TrackerOptionsPage(ITrackerComponent) it is recognised as implementing IClickRecorder and IsVisible is set to true. 当我通过ClickTracker作为参数传递给TrackerOptionsPage(ITrackerComponent)它是公认的实现IClickRecorder和可见性设置为true。

However, when I pass a ClicksLeftTracker as a parameter, it's set to false as if it's not implementing IClickRecorder . 但是,当我将ClicksLeftTracker作为参数传递时,会将其设置为false,就好像未实现IClickRecorder

The full flow from start to the method in question is: 从开始到有问题的方法的完整流程是:

// GetAllTrackers() returns IEnumerable<ITrackerComponent>
var allTrackers = _dataSource.GetAllTrackers();
allTrackers.ToList().ForEach(AddItemToGrid);

private void AddItemToGrid(ITrackerComponent item) {
    item.OnOptionsClick = 
        new Command(async () => await Navigation?.PushAsync(new TrackerOptionsPage(item, _dataSource)));
    // ...
}

public TrackerOptionsPage(ITrackerComponent trackerToShow) {
    ClickDatasSettings.IsVisible = trackerToShow is IClickRecorder;
    // ...
}

What is going on here? 这里发生了什么?

I solved it by manually uninstalling the app from the android emulator I was using and running it from Xamarin studio again. 我通过手动从正在使用的android模拟器中卸载应用程序并再次从Xamarin Studio中运行来解决该问题。

Seems there was some old assembly that wasn't being updated correctly on clean/rebuild, and it's probably related to me using two different computers with one having Xamarin Studio (OSX) and one having Visual Studio (Windows) when developing. 似乎有一些旧的装配在清理/重建时未正确更新,这可能与我使用两台不同的计算机有关,其中一台具有Xamarin Studio(OSX),一台具有Visual Studio(Windows)。

Thes issue with assemblies not updating on rebuild which lead me to my conclusion was found here. 程序集未在重建时更新的问题在这里找到了我的结论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM